From fadf8fdf81968c96b8055a722339ce947f3e4fd8 Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe Date: Thu, 7 Nov 2024 21:32:42 +0200 Subject: [PATCH] wip on elections --- app/Events/CountryCodeNotFound.php | 1 - app/Http/Controllers/Api/V1/Nomenclature.php | 19 -- .../Api/V1/NomenclatureController.php | 57 ++++ .../Controllers/Api/V1/TurnoutController.php | 16 + app/Http/Resources/CountryResource.php | 24 ++ app/Http/Resources/CountyResource.php | 28 ++ app/Http/Resources/LocationResource.php | 24 ++ .../Nomenclature/ElectionResource.php | 6 +- app/Providers/AppServiceProvider.php | 6 + composer.json | 1 + composer.lock | 295 +++++++++++------- config/scramble.php | 86 +++++ ...34_create_personal_access_tokens_table.php | 33 -- .../views/components/layouts/base.blade.php | 1 + resources/views/vendor/scramble/.gitkeep | 0 .../views/vendor/scramble/docs.blade.php | 62 ++++ routes/api.php | 34 +- 17 files changed, 525 insertions(+), 168 deletions(-) delete mode 100644 app/Http/Controllers/Api/V1/Nomenclature.php create mode 100644 app/Http/Controllers/Api/V1/NomenclatureController.php create mode 100644 app/Http/Controllers/Api/V1/TurnoutController.php create mode 100644 app/Http/Resources/CountryResource.php create mode 100644 app/Http/Resources/CountyResource.php create mode 100644 app/Http/Resources/LocationResource.php create mode 100644 config/scramble.php delete mode 100644 database/migrations/2024_11_05_063934_create_personal_access_tokens_table.php create mode 100644 resources/views/vendor/scramble/.gitkeep create mode 100644 resources/views/vendor/scramble/docs.blade.php diff --git a/app/Events/CountryCodeNotFound.php b/app/Events/CountryCodeNotFound.php index 6590102..bdd3366 100644 --- a/app/Events/CountryCodeNotFound.php +++ b/app/Events/CountryCodeNotFound.php @@ -6,7 +6,6 @@ use App\Models\Election; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/app/Http/Controllers/Api/V1/Nomenclature.php b/app/Http/Controllers/Api/V1/Nomenclature.php deleted file mode 100644 index 0b76f2a..0000000 --- a/app/Http/Controllers/Api/V1/Nomenclature.php +++ /dev/null @@ -1,19 +0,0 @@ -orderBy('is_live')->get(); - - return response()->json(ElectionResource::collection($elections)); - } -} diff --git a/app/Http/Controllers/Api/V1/NomenclatureController.php b/app/Http/Controllers/Api/V1/NomenclatureController.php new file mode 100644 index 0000000..57bb523 --- /dev/null +++ b/app/Http/Controllers/Api/V1/NomenclatureController.php @@ -0,0 +1,57 @@ +json( + ElectionResource::collection( + Election::query() + ->orderBy('is_live', 'desc') + ->get() + ) + ); + } + + public function counties(): JsonResponse + { + return response()->json( + CountyResource::collection( + County::with(['localities' => function ($query) { + $query->whereNull('parent_id'); + }])->get() + ) + ); + } + + public function county(County $county): JsonResponse + { + return response()->json( + new CountyResource( + $county->load('localities') + ) + ); + } + + public function countries(): JsonResponse + { + return response()->json( + CountryResource::collection( + Country::all() + ) + ); + } +} diff --git a/app/Http/Controllers/Api/V1/TurnoutController.php b/app/Http/Controllers/Api/V1/TurnoutController.php new file mode 100644 index 0000000..2944d8b --- /dev/null +++ b/app/Http/Controllers/Api/V1/TurnoutController.php @@ -0,0 +1,16 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + ]; + } +} diff --git a/app/Http/Resources/CountyResource.php b/app/Http/Resources/CountyResource.php new file mode 100644 index 0000000..6dbb508 --- /dev/null +++ b/app/Http/Resources/CountyResource.php @@ -0,0 +1,28 @@ + + */ + public function toArray(Request $request): array + { + /* @var County $this */ + return [ + 'id' => $this->id, + 'name' => $this->name, + 'code' => $this->code, + 'localities' => LocationResource::collection(($this->whenLoaded('localities'))), + ]; + } +} diff --git a/app/Http/Resources/LocationResource.php b/app/Http/Resources/LocationResource.php new file mode 100644 index 0000000..a7d8637 --- /dev/null +++ b/app/Http/Resources/LocationResource.php @@ -0,0 +1,24 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + ]; + } +} diff --git a/app/Http/Resources/Nomenclature/ElectionResource.php b/app/Http/Resources/Nomenclature/ElectionResource.php index d632a73..bc5749c 100644 --- a/app/Http/Resources/Nomenclature/ElectionResource.php +++ b/app/Http/Resources/Nomenclature/ElectionResource.php @@ -1,7 +1,10 @@ $this->id, 'title' => $this->title, 'subtitle' => $this->subtitle, + 'type' => $this->type->getLabel(), 'is_live' => $this->is_live, 'slug' => $this->slug, 'created_at' => $this->created_at, ]; } - } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3cca760..1794aff 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -5,9 +5,11 @@ namespace App\Providers; use App\Models\ScheduledJob; +use Dedoc\Scramble\Scramble; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\QueryException; +use Illuminate\Routing\Route; use Illuminate\Support\Number; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; @@ -42,6 +44,10 @@ public function boot(): void $this->resolveSchedule(); $this->setSeoDefaults(); + + Scramble::routes(function (Route $route) { + return Str::startsWith($route->uri, 'api/'); + }); } protected function registerStrMacros(): void diff --git a/composer.json b/composer.json index 45bd7f7..191cdc3 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "andreiio/blade-remix-icon": "^3.5", "archtechx/laravel-seo": "^0.10.1", "blade-ui-kit/blade-icons": "^1.7", + "dedoc/scramble": "^0.11.25", "filament/filament": "^3.2", "filament/spatie-laravel-media-library-plugin": "^3.2", "haydenpierce/class-finder": "^0.5.3", diff --git a/composer.lock b/composer.lock index 4aaf79d..426b653 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "59db1a7c45bb17b3e1afc31c9384d16d", + "content-hash": "1403f6fb816c29a8f091c0b0160cd5b8", "packages": [ { "name": "andreiio/blade-remix-icon", @@ -975,6 +975,81 @@ }, "time": "2024-08-09T14:30:48+00:00" }, + { + "name": "dedoc/scramble", + "version": "v0.11.25", + "source": { + "type": "git", + "url": "https://github.com/dedoc/scramble.git", + "reference": "9bef930238e37d53e9ac5c459412fef6f0d7e27a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dedoc/scramble/zipball/9bef930238e37d53e9ac5c459412fef6f0d7e27a", + "reference": "9bef930238e37d53e9ac5c459412fef6f0d7e27a", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^10.0|^11.0", + "myclabs/deep-copy": "^1.12", + "nikic/php-parser": "^5.0", + "php": "^8.1", + "phpstan/phpdoc-parser": "^1.0", + "spatie/laravel-package-tools": "^1.9.2" + }, + "require-dev": { + "laravel/pint": "^v1.1.0", + "nunomaduro/collision": "^7.0|^8.0", + "orchestra/testbench": "^8.0|^9.0", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-laravel": "^2.3", + "phpunit/phpunit": "^10.5", + "spatie/pest-plugin-snapshots": "^2.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Dedoc\\Scramble\\ScrambleServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Dedoc\\Scramble\\": "src", + "Dedoc\\Scramble\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Lytvynenko", + "email": "litvinenko95@gmail.com", + "role": "Developer" + } + ], + "description": "Automatic generation of API documentation for Laravel applications.", + "homepage": "https://github.com/dedoc/scramble", + "keywords": [ + "documentation", + "laravel", + "openapi" + ], + "support": { + "issues": "https://github.com/dedoc/scramble/issues", + "source": "https://github.com/dedoc/scramble/tree/v0.11.25" + }, + "funding": [ + { + "url": "https://github.com/romalytvynenko", + "type": "github" + } + ], + "time": "2024-11-06T11:13:17+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.3", @@ -4750,6 +4825,66 @@ }, "time": "2024-09-04T18:46:31+00:00" }, + { + "name": "myclabs/deep-copy", + "version": "1.12.0", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3 <3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2024-06-12T14:39:25+00:00" + }, { "name": "nesbot/carbon", "version": "3.8.1", @@ -5893,6 +6028,53 @@ ], "time": "2024-07-20T21:41:07+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.33.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" + }, + "time": "2024-10-13T11:25:22+00:00" + }, { "name": "pragmarx/google2fa", "version": "v8.0.3", @@ -11720,66 +11902,6 @@ }, "time": "2024-05-16T03:13:13+00:00" }, - { - "name": "myclabs/deep-copy", - "version": "1.12.0", - "source": { - "type": "git", - "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "conflict": { - "doctrine/collections": "<1.6.8", - "doctrine/common": "<2.13.3 || >=3 <3.2.2" - }, - "require-dev": { - "doctrine/collections": "^1.6.8", - "doctrine/common": "^2.13.3 || ^3.2.2", - "phpspec/prophecy": "^1.10", - "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" - }, - "type": "library", - "autoload": { - "files": [ - "src/DeepCopy/deep_copy.php" - ], - "psr-4": { - "DeepCopy\\": "src/DeepCopy/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Create deep copies (clones) of your objects", - "keywords": [ - "clone", - "copy", - "duplicate", - "object", - "object graph" - ], - "support": { - "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" - }, - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", - "type": "tidelift" - } - ], - "time": "2024-06-12T14:39:25+00:00" - }, { "name": "nunomaduro/collision", "version": "v8.5.0", @@ -12193,53 +12315,6 @@ ], "time": "2024-08-29T20:56:34+00:00" }, - { - "name": "phpstan/phpdoc-parser", - "version": "1.33.0", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", - "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "require-dev": { - "doctrine/annotations": "^2.0", - "nikic/php-parser": "^4.15", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.5", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^9.5", - "symfony/process": "^5.2" - }, - "type": "library", - "autoload": { - "psr-4": { - "PHPStan\\PhpDocParser\\": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPDoc parser with support for nullable, intersection and generic types", - "support": { - "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" - }, - "time": "2024-10-13T11:25:22+00:00" - }, { "name": "phpstan/phpstan", "version": "1.12.7", @@ -14882,12 +14957,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, "platform": { "php": "^8.2" }, - "platform-dev": {}, + "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/config/scramble.php b/config/scramble.php new file mode 100644 index 0000000..2d96016 --- /dev/null +++ b/config/scramble.php @@ -0,0 +1,86 @@ + 'api', + + /* + * Your API domain. By default, app domain is used. This is also a part of the default API routes + * matcher, so when implementing your own, make sure you use this config if needed. + */ + 'api_domain' => null, + + /* + * The path where your OpenAPI specification will be exported. + */ + 'export_path' => 'api.json', + + 'info' => [ + /* + * API version. + */ + 'version' => env('API_VERSION', '0.0.1'), + + /* + * Description rendered on the home page of the API documentation (`/docs/api`). + */ + 'description' => '', + ], + + /* + * Customize Stoplight Elements UI + */ + 'ui' => [ + /* + * Define the title of the documentation's website. App name is used when this config is `null`. + */ + 'title' => null, + + /* + * Define the theme of the documentation. Available options are `light` and `dark`. + */ + 'theme' => 'light', + + /* + * Hide the `Try It` feature. Enabled by default. + */ + 'hide_try_it' => false, + + /* + * URL to an image that displays as a small square logo next to the title, above the table of contents. + */ + 'logo' => null, + + /* + * Use to fetch the credential policy for the Try It feature. Options are: omit, include (default), and same-origin + */ + 'try_it_credentials_policy' => 'include', + ], + + /* + * The list of servers of the API. By default, when `null`, server URL will be created from + * `scramble.api_path` and `scramble.api_domain` config variables. When providing an array, you + * will need to specify the local server URL manually (if needed). + * + * Example of non-default config (final URLs are generated using Laravel `url` helper): + * + * ```php + * 'servers' => [ + * 'Live' => 'api', + * 'Prod' => 'https://scramble.dedoc.co/api', + * ], + * ``` + */ + 'servers' => null, + + 'middleware' => [ + 'web', + ], + + 'extensions' => [], +]; diff --git a/database/migrations/2024_11_05_063934_create_personal_access_tokens_table.php b/database/migrations/2024_11_05_063934_create_personal_access_tokens_table.php deleted file mode 100644 index e828ad8..0000000 --- a/database/migrations/2024_11_05_063934_create_personal_access_tokens_table.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - $table->morphs('tokenable'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamp('expires_at')->nullable(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('personal_access_tokens'); - } -}; diff --git a/resources/views/components/layouts/base.blade.php b/resources/views/components/layouts/base.blade.php index 07f28b0..263f586 100644 --- a/resources/views/components/layouts/base.blade.php +++ b/resources/views/components/layouts/base.blade.php @@ -16,6 +16,7 @@ @filamentStyles @vite('resources/css/app.css') +