3.1-3.6: install l5-swagger, add @OA annotations to all controllers
This commit is contained in:
1 parent
db7ce880a0
commit
afb202f333
13 files changed
+1367
-73
No files matched your search
@@ -8,8 +8,22 @@ use App\Http\Requests\Website\UpdateProjectRequest;
|
||||
use App\Models\Website\Project;
|
||||
use App\Models\Website\ProjectCategory;
|
||||
|
||||
/**
|
||||
* @OA\Tag(name="Projects", description="Projects section endpoints")
|
||||
*/
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/website/projects/translation/{locale}",
|
||||
* tags={"Projects"},
|
||||
* summary="List projects and categories in a locale",
|
||||
* @OA\Parameter(name="locale", in="path", required=true, @OA\Schema(type="string", enum={"fa","en"})),
|
||||
* @OA\Parameter(name="per_page", in="query", @OA\Schema(type="integer")),
|
||||
* @OA\Parameter(name="sort", in="query", @OA\Schema(type="string", enum={"asc","desc"})),
|
||||
* @OA\Response(response=200, description="OK")
|
||||
* )
|
||||
*/
|
||||
public function index($locale): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$perPage = request()->query('per_page', 10);
|
||||
@@ -48,6 +62,15 @@ class ProjectController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/website/projects",
|
||||
* tags={"Projects"},
|
||||
* summary="Create a project",
|
||||
* @OA\RequestBody(@OA\MediaType(mediaType="application/json")),
|
||||
* @OA\Response(response=201, description="Created")
|
||||
* )
|
||||
*/
|
||||
public function store(StoreProjectRequest $request)
|
||||
{
|
||||
$project = Project::create($request->only(['category_id', 'image1', 'image2']));
|
||||
@@ -61,6 +84,16 @@ class ProjectController extends Controller
|
||||
return response()->json($project, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/website/projects/{id}/translation/{locale}",
|
||||
* tags={"Projects"},
|
||||
* summary="Get a single project 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 show($id, $locale)
|
||||
{
|
||||
$project = Project::with('category')->findOrFail($id);
|
||||
@@ -68,7 +101,7 @@ class ProjectController extends Controller
|
||||
$formattedProject = [
|
||||
'id' => $project->id,
|
||||
'title' => $project->getTranslation('title', $locale),
|
||||
'category' => $project->category?->getTranslation('title', 'fa'),
|
||||
'category' => $project->category?->getTranslation('title', $locale),
|
||||
'images' => [
|
||||
['src' => $project->image1, 'position' => '1', 'zIndex' => 1],
|
||||
['src' => $project->image2, 'position' => '2', 'zIndex' => 2],
|
||||
@@ -80,6 +113,16 @@ class ProjectController extends Controller
|
||||
return response()->json(['project' => $formattedProject]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Put(
|
||||
* path="/website/projects/{id}",
|
||||
* tags={"Projects"},
|
||||
* summary="Update a project",
|
||||
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
|
||||
* @OA\RequestBody(@OA\MediaType(mediaType="application/json")),
|
||||
* @OA\Response(response=200, description="OK")
|
||||
* )
|
||||
*/
|
||||
public function update(UpdateProjectRequest $request, $id)
|
||||
{
|
||||
$project = Project::findOrFail($id);
|
||||
@@ -98,6 +141,15 @@ class ProjectController extends Controller
|
||||
return response()->json($project);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Delete(
|
||||
* path="/website/projects/{id}",
|
||||
* tags={"Projects"},
|
||||
* summary="Delete a project",
|
||||
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
|
||||
* @OA\Response(response=204, description="No Content")
|
||||
* )
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
Project::destroy($id);
|
||||
|
||||
Reference in new issue
Block a user