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
@@ -7,26 +7,65 @@ use App\Http\Requests\Website\StoreAboutMeRequest;
|
||||
use App\Http\Requests\Website\UpdateAboutMeRequest;
|
||||
use App\Models\Website\AboutMe;
|
||||
|
||||
/**
|
||||
* @OA\Tag(name="About Me", description="About Me section endpoints")
|
||||
*/
|
||||
class AboutMeController extends Controller
|
||||
{
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/website/about-me",
|
||||
* tags={"About Me"},
|
||||
* summary="Get the first About Me entry with skills",
|
||||
* @OA\Response(response=200, description="OK", @OA\JsonContent(ref="#/components/schemas/AboutMe"))
|
||||
* )
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$aboutMe = AboutMe::with('skills')->first();
|
||||
return response()->json($aboutMe);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/website/about-me/{id}",
|
||||
* tags={"About Me"},
|
||||
* summary="Get a specific About Me entry",
|
||||
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
|
||||
* @OA\Response(response=200, description="OK")
|
||||
* )
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$aboutMe = AboutMe::with('skills')->findOrFail($id);
|
||||
return response()->json($aboutMe);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/website/about-me",
|
||||
* tags={"About Me"},
|
||||
* summary="Create an About Me entry",
|
||||
* @OA\RequestBody(@OA\MediaType(mediaType="application/json")),
|
||||
* @OA\Response(response=201, description="Created")
|
||||
* )
|
||||
*/
|
||||
public function store(StoreAboutMeRequest $request)
|
||||
{
|
||||
$aboutMe = AboutMe::create($request->validated());
|
||||
return response()->json($aboutMe, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Put(
|
||||
* path="/website/about-me/{id}",
|
||||
* tags={"About Me"},
|
||||
* summary="Update an About Me entry",
|
||||
* @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(UpdateAboutMeRequest $request, $id)
|
||||
{
|
||||
$aboutMe = AboutMe::findOrFail($id);
|
||||
@@ -34,12 +73,32 @@ class AboutMeController extends Controller
|
||||
return response()->json($aboutMe);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Delete(
|
||||
* path="/website/about-me/{id}",
|
||||
* tags={"About Me"},
|
||||
* summary="Delete an About Me entry",
|
||||
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer")),
|
||||
* @OA\Response(response=204, description="No Content")
|
||||
* )
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
AboutMe::destroy($id);
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/website/about-me/{id}/translation/{locale}",
|
||||
* tags={"About Me"},
|
||||
* summary="Get localized About Me with skills",
|
||||
* @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", @OA\JsonContent(ref="#/components/schemas/AboutMe")),
|
||||
* @OA\Response(response=404, description="Translation not found")
|
||||
* )
|
||||
*/
|
||||
public function getTranslation($id, $locale)
|
||||
{
|
||||
$aboutMe = AboutMe::with('skills')->findOrFail($id);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -5,8 +5,20 @@ 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();
|
||||
@@ -26,6 +38,16 @@ class ServiceController extends Controller
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user