Skip to content

Commit

Permalink
feat: personnel index api (for docchula homepage)
Browse files Browse the repository at this point in the history
  • Loading branch information
keenthekeen committed Oct 26, 2023
1 parent 2d23f11 commit e5ff52b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/Http/Controllers/PersonnelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ public function index(Request $request)
]);
}

public function indexApi(Request $request)
{
$yearList = Personnel::getYearList();
$list = Personnel::getYear($request->input('year', $yearList[0]))->map(function (Personnel $personnel) {
$personnel->photo_url = $personnel->photo_path ? Storage::disk('public')->url($personnel->photo_path) : null;
return $personnel;
})->only(['id', 'name', 'name_en', 'position', 'position_en', 'year', 'sequence', 'photo_url']);
return response()->json([
'years' => $yearList,
'personnels' => $list,
]);
}

public function create(Request $request)
{
return $this->edit(new Personnel(['year' => $request->input('year') ?? Helper::buddhistYear()]));
Expand Down
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});

Route::get('personnels', [\App\Http\Controllers\PersonnelController::class, 'indexApi']);

0 comments on commit e5ff52b

Please sign in to comment.