feat: add read-only Sites API

Add GET /api/sites endpoint for listing sites with optional name filter,
and GET /api/sites/{site} for showing individual sites. Includes API
resource, controller, routes registration, and comprehensive tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-07-18 15:12:44 +03:00
co-authored by Claude Sonnet 5
parent cee5b1976b
commit 20c33f1c23
5 changed files with 90 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
use App\Models\Site;
test('it lists all sites', function () {
Site::factory()->count(3)->create();
$response = $this->getJson('/api/sites');
$response->assertOk()->assertJsonCount(3, 'data');
});
test('it filters sites by partial name match', function () {
Site::factory()->create(['name' => 'My Awesome Blog']);
Site::factory()->create(['name' => 'Other Site']);
$response = $this->getJson('/api/sites?name=Awesome');
$response->assertOk()
->assertJsonCount(1, 'data')
->assertJsonPath('data.0.name', 'My Awesome Blog');
});
test('it shows a single site', function () {
$site = Site::factory()->create(['name' => 'Solo Site']);
$response = $this->getJson("/api/sites/{$site->id}");
$response->assertOk()->assertJsonPath('data.name', 'Solo Site');
});
test('it returns 404 for a missing site', function () {
$this->getJson('/api/sites/999')->assertNotFound();
});