54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
|
|
use App\Models\Department;
|
|
|
|
class DepartmentController extends Controller
|
|
{
|
|
/**
|
|
* GET /Departments
|
|
* Query params:
|
|
* - departmentName (string)
|
|
* - updatedSince (date-time)
|
|
*/
|
|
public function index(Request $request) {
|
|
$q = Department::query();
|
|
|
|
if ($name = $request->query('departmentName')) {
|
|
$q->where('name', $name);
|
|
}
|
|
|
|
if ($since = $request->query('updatedSince')) {
|
|
$q->where('updated_at', '>=', Carbon::parse($since));
|
|
}
|
|
|
|
$out = $q->get()->map(function ($d) {
|
|
return [
|
|
'Id' => $d->id,
|
|
'Name' => $d->name,
|
|
'Updated' => $d->updated_at->toIso8601String().'Z',
|
|
];
|
|
});
|
|
|
|
return response()->json($out);
|
|
}
|
|
|
|
/**
|
|
* GET /Departments/{id}
|
|
*/
|
|
public function show(int $id) {
|
|
$d = Department::findOrFail($id);
|
|
|
|
return response()->json([
|
|
'Id' => $d->id,
|
|
'Name' => $d->name,
|
|
'Updated' => $d->updated_at->toIso8601String().'Z',
|
|
]);
|
|
}
|
|
}
|