63 lines
2.1 KiB
PHP
63 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Website;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Website\Service;
|
|
|
|
/**
|
|
* @OA\Tag(name="Services", description="Services section endpoints")
|
|
*/
|
|
class ServiceController extends Controller
|
|
{
|
|
/**
|
|
* @OA\Get(
|
|
* path="/website/services/{locale}",
|
|
* tags={"Services"},
|
|
* summary="List all services in a given locale",
|
|
* @OA\Parameter(name="locale", in="path", required=true, @OA\Schema(type="string", enum={"fa","en"})),
|
|
* @OA\Response(response=200, description="OK", @OA\JsonContent(type="array", @OA\Items(ref="#/components/schemas/Service")))
|
|
* )
|
|
*/
|
|
public function index($locale)
|
|
{
|
|
$services = Service::all();
|
|
|
|
$response = $services->map(function ($service) use ($locale) {
|
|
return [
|
|
'id' => $service->id,
|
|
'imageSrc' => $service->imageSrc,
|
|
'altText' => '',
|
|
'created_at' => $service->created_at,
|
|
'updated_at' => $service->updated_at,
|
|
'title' => $service->getTranslation('title', $locale),
|
|
'description' => $service->getTranslation('description', $locale),
|
|
];
|
|
});
|
|
|
|
return response()->json($response);
|
|
}
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/website/services/{id}/translation/{locale}",
|
|
* tags={"Services"},
|
|
* summary="Get a single service translation",
|
|
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
|
|
* @OA\Parameter(name="locale", in="path", required=true, @OA\Schema(type="string", enum={"fa","en"})),
|
|
* @OA\Response(response=200, description="OK")
|
|
* )
|
|
*/
|
|
public function showTranslation($id, $locale)
|
|
{
|
|
$service = Service::findOrFail($id);
|
|
|
|
return response()->json([
|
|
'id' => $service->id,
|
|
'imageSrc' => $service->imageSrc,
|
|
'title' => $service->getTranslation('title', $locale),
|
|
'description' => $service->getTranslation('description', $locale),
|
|
]);
|
|
}
|
|
}
|