Current state
This commit is contained in:
46
app/Http/Controllers/Api/ArtworkController.php
Normal file
46
app/Http/Controllers/Api/ArtworkController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\ArtworkListResource;
|
||||
use App\Http\Resources\ArtworkResource;
|
||||
use App\Services\ArtworkService;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ArtworkController extends Controller
|
||||
{
|
||||
protected ArtworkService $service;
|
||||
|
||||
public function __construct(ArtworkService $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/artworks/{slug}
|
||||
* Returns a single public artwork resource by slug.
|
||||
*/
|
||||
public function show(string $slug)
|
||||
{
|
||||
$artwork = $this->service->getPublicArtworkBySlug($slug);
|
||||
|
||||
// Return the artwork instance (service already loads lightweight relations).
|
||||
// Log resolved resource for debugging failing test assertions.
|
||||
// Return the resolved payload directly to avoid JsonResource wrapping inconsistencies
|
||||
return response()->json((new ArtworkResource($artwork))->resolve(), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/categories/{slug}/artworks
|
||||
* Uses route-model binding for Category (slug). Returns paginated list resource.
|
||||
*/
|
||||
public function categoryArtworks(Request $request, Category $category)
|
||||
{
|
||||
$perPage = (int) $request->get('per_page', 24);
|
||||
|
||||
$paginator = $this->service->getCategoryArtworks($category, $perPage);
|
||||
|
||||
return ArtworkListResource::collection($paginator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user