Files
bogazici-api/app/Http/Controllers/Api/V1/MenuController.php
2026-03-27 10:41:54 +03:00

37 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Api\V1;
use App\Enums\MenuLocation;
use App\Http\Controllers\Controller;
use App\Http\Resources\MenuResource;
use App\Repositories\Contracts\MenuRepositoryInterface;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use OpenApi\Attributes as OA;
class MenuController extends Controller
{
public function __construct(private MenuRepositoryInterface $repository) {}
#[OA\Get(
path: '/api/v1/menus/{location}',
summary: 'Konuma göre menü öğelerini getir',
tags: ['Menus'],
parameters: [new OA\Parameter(name: 'location', in: 'path', required: true, schema: new OA\Schema(type: 'string'), description: 'header, footer, mobile')],
responses: [
new OA\Response(response: 200, description: 'Menü listesi'),
new OA\Response(response: 404, description: 'Menü konumu bulunamadı'),
],
)]
public function index(string $location): AnonymousResourceCollection
{
$menuLocation = MenuLocation::tryFrom($location);
if (! $menuLocation) {
abort(404, 'Menü konumu bulunamadı.');
}
return MenuResource::collection($this->repository->getByLocation($menuLocation));
}
}