Skip to content

Commit

Permalink
add general turnouts
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Nov 7, 2024
1 parent 8498516 commit 360b5e4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/Http/Controllers/Api/V1/TurnoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@

namespace App\Http\Controllers\Api\V1;

use App\Enums\DataLevel;
use App\Http\Controllers\Controller;
use App\Http\Resources\TurnoutResource;
use App\Models\Election;
use App\Models\Turnout;
use Illuminate\Http\JsonResponse;

class TurnoutController extends Controller
{
public function turnout(Election $election)
public function general(Election $election): JsonResponse
{
dd($election);
$result = Turnout::query()
->whereBelongsTo($election)
->forLevel(
level: DataLevel::TOTAL,
)
->toBase()
->first();

return response()->json(TurnoutResource::make($result));
}
}
24 changes: 24 additions & 0 deletions app/Http/Resources/TurnoutResource.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 TurnoutResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'initial_total' => $this->initial_total,
'total' => $this->total,
];
}
}

0 comments on commit 360b5e4

Please sign in to comment.