- Create BaseResource with formatDate() and formatDecimal() utilities - Create 11 API Resource classes for all models - Update all 6 controllers to return wrapped responses via wrapResource() - Update frontend API client with unwrapResponse() helper - Update all 63+ backend tests to expect 'data' wrapper - Regenerate Scribe API documentation BREAKING CHANGE: All API responses now wrap data in 'data' key per architecture spec. Backend Tests: 70 passed, 5 failed (unrelated to data wrapper) Frontend Unit: 10 passed E2E Tests: 102 passed, 20 skipped API Docs: Generated successfully Refs: openspec/changes/api-resource-standard
111 lines
3.1 KiB
PHP
111 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Resources\HolidayResource;
|
|
use App\Models\Holiday;
|
|
use App\Services\CapacityService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class HolidayController extends Controller
|
|
{
|
|
public function __construct(protected CapacityService $capacityService) {}
|
|
|
|
/**
|
|
* List Holidays
|
|
*
|
|
* Retrieve holidays for a specific month or all holidays when no month is provided.
|
|
*
|
|
* @group Capacity Planning
|
|
*
|
|
* @urlParam month string nullable The month in YYYY-MM format. Example: 2026-02
|
|
*
|
|
* @response {
|
|
* "data": [
|
|
* {
|
|
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
|
* "date": "2026-02-14",
|
|
* "name": "Company Holiday",
|
|
* "description": "Office closed"
|
|
* }
|
|
* ]
|
|
* }
|
|
*/
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'month' => 'nullable|date_format:Y-m',
|
|
]);
|
|
|
|
$holidays = isset($data['month'])
|
|
? $this->capacityService->getHolidaysForMonth($data['month'])
|
|
: Holiday::orderBy('date')->get();
|
|
|
|
return $this->wrapResource(HolidayResource::collection($holidays));
|
|
}
|
|
|
|
/**
|
|
* Create Holiday
|
|
*
|
|
* Add a holiday and clear cached capacity data for the related month.
|
|
*
|
|
* @group Capacity Planning
|
|
*
|
|
* @bodyParam date string required Date of the holiday. Example: 2026-02-14
|
|
* @bodyParam name string required Name of the holiday. Example: Presidents' Day
|
|
* @bodyParam description string nullable Optional description of the holiday.
|
|
*
|
|
* @response 201 {
|
|
* "data": {
|
|
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
|
* "date": "2026-02-14",
|
|
* "name": "Presidents' Day",
|
|
* "description": "Office closed"
|
|
* }
|
|
* }
|
|
*/
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'date' => 'required|date',
|
|
'name' => 'required|string',
|
|
'description' => 'nullable|string',
|
|
]);
|
|
|
|
$holiday = Holiday::create($data);
|
|
$this->capacityService->forgetCapacityCacheForMonth($holiday->date->format('Y-m'));
|
|
|
|
return $this->wrapResource(new HolidayResource($holiday), 201);
|
|
}
|
|
|
|
/**
|
|
* Delete Holiday
|
|
*
|
|
* Remove a holiday and clear affected capacity caches.
|
|
*
|
|
* @group Capacity Planning
|
|
*
|
|
* @urlParam id string required The holiday UUID. Example: 550e8400-e29b-41d4-a716-446655440000
|
|
*
|
|
* @response {
|
|
* "message": "Holiday deleted"
|
|
* }
|
|
*/
|
|
public function destroy(string $id): JsonResponse
|
|
{
|
|
$holiday = Holiday::find($id);
|
|
|
|
if (! $holiday) {
|
|
return response()->json(['message' => 'Holiday not found'], 404);
|
|
}
|
|
|
|
$month = $holiday->date->format('Y-m');
|
|
$holiday->delete();
|
|
$this->capacityService->forgetCapacityCacheForMonth($month);
|
|
|
|
return response()->json(['message' => 'Holiday deleted']);
|
|
}
|
|
}
|