feat(api): Implement API Resource Standard compliance
- 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
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
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;
|
||||
@@ -18,15 +19,19 @@ class HolidayController extends Controller
|
||||
* 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 [
|
||||
* {
|
||||
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
* "date": "2026-02-14",
|
||||
* "name": "Company Holiday",
|
||||
* "description": "Office closed"
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
* @response {
|
||||
* "data": [
|
||||
* {
|
||||
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
* "date": "2026-02-14",
|
||||
* "name": "Company Holiday",
|
||||
* "description": "Office closed"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@@ -38,7 +43,7 @@ class HolidayController extends Controller
|
||||
? $this->capacityService->getHolidaysForMonth($data['month'])
|
||||
: Holiday::orderBy('date')->get();
|
||||
|
||||
return response()->json($holidays);
|
||||
return $this->wrapResource(HolidayResource::collection($holidays));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,14 +52,18 @@ class HolidayController extends Controller
|
||||
* 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 {
|
||||
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
* "date": "2026-02-14",
|
||||
* "name": "Presidents' Day",
|
||||
* "description": "Office closed"
|
||||
* "data": {
|
||||
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
* "date": "2026-02-14",
|
||||
* "name": "Presidents' Day",
|
||||
* "description": "Office closed"
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
@@ -68,7 +77,7 @@ class HolidayController extends Controller
|
||||
$holiday = Holiday::create($data);
|
||||
$this->capacityService->forgetCapacityCacheForMonth($holiday->date->format('Y-m'));
|
||||
|
||||
return response()->json($holiday, 201);
|
||||
return $this->wrapResource(new HolidayResource($holiday), 201);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +86,9 @@ class HolidayController extends Controller
|
||||
* 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"
|
||||
* }
|
||||
|
||||
Reference in New Issue
Block a user