Skip to content

Commit

Permalink
wip on elections
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Nov 7, 2024
1 parent 012db8b commit fadf8fd
Show file tree
Hide file tree
Showing 17 changed files with 525 additions and 168 deletions.
1 change: 0 additions & 1 deletion app/Events/CountryCodeNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
19 changes: 0 additions & 19 deletions app/Http/Controllers/Api/V1/Nomenclature.php

This file was deleted.

57 changes: 57 additions & 0 deletions app/Http/Controllers/Api/V1/NomenclatureController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Http\Resources\CountryResource;
use App\Http\Resources\CountyResource;
use App\Http\Resources\Nomenclature\ElectionResource;
use App\Models\Country;
use App\Models\County;
use App\Models\Election;
use Illuminate\Http\JsonResponse;

class NomenclatureController extends Controller
{
public function elections(): JsonResponse
{
return response()->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()
)
);
}
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/Api/V1/TurnoutController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Models\Election;

class TurnoutController extends Controller
{
public function turnout(Election $election)
{
dd($election);
}
}
24 changes: 24 additions & 0 deletions app/Http/Resources/CountryResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class CountryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
];
}
}
28 changes: 28 additions & 0 deletions app/Http/Resources/CountyResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use App\Models\County;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class CountyResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
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'))),
];
}
}
24 changes: 24 additions & 0 deletions app/Http/Resources/LocationResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class LocationResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
];
}
}
6 changes: 5 additions & 1 deletion app/Http/Resources/Nomenclature/ElectionResource.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources\Nomenclature;

use App\Models\Election;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

Expand All @@ -14,14 +17,15 @@ class ElectionResource extends JsonResource
*/
public function toArray(Request $request): array
{
/* @var Election $this */
return [
'id' => $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,
];
}

}
6 changes: 6 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit fadf8fd

Please sign in to comment.