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:
2026-02-19 14:51:56 -05:00
parent 1592c5be8d
commit 47068dabce
49 changed files with 2426 additions and 809 deletions

View File

@@ -0,0 +1,32 @@
<?php
use App\Http\Resources\TeamMemberResource;
use App\Models\Role;
use App\Models\TeamMember;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
test('team member resource wraps data and includes role when loaded', function () {
$role = Role::factory()->create();
$teamMember = TeamMember::factory()->create(['role_id' => $role->id]);
$teamMember->load('role');
$response = (new TeamMemberResource($teamMember))->toResponse(Request::create('/'));
$payload = $response->getData(true);
expect($payload['data']['id'])->toBe($teamMember->id);
expect($payload['data']['role']['id'])->toBe($role->id);
});
test('team member resource collection keeps data wrapper', function () {
$role = Role::factory()->create();
$teamMembers = TeamMember::factory()->count(2)->create(['role_id' => $role->id]);
$response = TeamMemberResource::collection($teamMembers)->toResponse(Request::create('/'));
$payload = $response->getData(true);
expect($payload['data'])->toHaveCount(2);
});