Files
sam-api/app/Http/Controllers/Api/V1/Design/ModelParameterController.php

227 lines
8.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\Api\V1\Design;
use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Services\ModelParameterService;
use App\Http\Requests\Api\V1\Design\ModelParameterFormRequest;
use App\Http\Requests\Api\V1\ModelParameter\IndexModelParameterRequest;
/**
* @OA\Tag(name="Model Parameters", description="Model parameter management APIs")
*/
class ModelParameterController extends Controller
{
public function __construct(
protected ModelParameterService $service
) {}
/**
* @OA\Get(
* path="/v1/design/models/{modelId}/parameters",
* summary="Get model parameters",
* description="Retrieve all parameters for a specific model",
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
* tags={"Model Parameters"},
* @OA\Parameter(
* name="modelId",
* description="Model ID",
* in="path",
* required=true,
* @OA\Schema(type="integer", example=1)
* ),
* @OA\Parameter(
* name="page",
* description="Page number for pagination",
* in="query",
* required=false,
* @OA\Schema(type="integer", example=1)
* ),
* @OA\Parameter(
* name="per_page",
* description="Items per page",
* in="query",
* required=false,
* @OA\Schema(type="integer", example=20)
* ),
* @OA\Parameter(
* name="search",
* description="Search by parameter name or label",
* in="query",
* required=false,
* @OA\Schema(type="string", example="width")
* ),
* @OA\Parameter(
* name="type",
* description="Filter by parameter type",
* in="query",
* required=false,
* @OA\Schema(type="string", enum={"INPUT", "OUTPUT"}, example="INPUT")
* ),
* @OA\Response(
* response=200,
* description="Model parameters retrieved successfully",
* @OA\JsonContent(
* allOf={
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
* @OA\Property(
* property="data",
* @OA\Property(
* property="data",
* type="array",
* @OA\Items(ref="#/components/schemas/ModelParameterResource")
* ),
* @OA\Property(property="current_page", type="integer", example=1),
* @OA\Property(property="last_page", type="integer", example=3),
* @OA\Property(property="per_page", type="integer", example=20),
* @OA\Property(property="total", type="integer", example=45)
* )
* )
* }
* )
* ),
* @OA\Response(ref="#/components/responses/ErrorResponse", response=400),
* @OA\Response(ref="#/components/responses/UnauthorizedResponse", response=401),
* @OA\Response(ref="#/components/responses/NotFoundResponse", response=404)
* )
*/
public function index(IndexModelParameterRequest $request, int $modelId)
{
return ApiResponse::handle(function () use ($request, $modelId) {
return $this->service->getModelParameters($modelId, $request->validated());
}, __('message.fetched'));
}
/**
* @OA\Post(
* path="/v1/design/models/{modelId}/parameters",
* summary="Create model parameter",
* description="Create a new parameter for a specific model",
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
* tags={"Model Parameters"},
* @OA\Parameter(
* name="modelId",
* description="Model ID",
* in="path",
* required=true,
* @OA\Schema(type="integer", example=1)
* ),
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(ref="#/components/schemas/CreateModelParameterRequest")
* ),
* @OA\Response(
* response=201,
* description="Model parameter created successfully",
* @OA\JsonContent(
* allOf={
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
* @OA\Property(property="data", ref="#/components/schemas/ModelParameterResource")
* )
* }
* )
* ),
* @OA\Response(ref="#/components/responses/ValidationErrorResponse", response=422),
* @OA\Response(ref="#/components/responses/ErrorResponse", response=400),
* @OA\Response(ref="#/components/responses/UnauthorizedResponse", response=401)
* )
*/
public function store(ModelParameterFormRequest $request, int $modelId)
{
return ApiResponse::handle(function () use ($request, $modelId) {
return $this->service->createParameter($modelId, $request->validated());
}, __('message.created'));
}
/**
* @OA\Put(
* path="/v1/design/models/{modelId}/parameters/{parameterId}",
* summary="Update model parameter",
* description="Update a specific model parameter",
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
* tags={"Model Parameters"},
* @OA\Parameter(
* name="modelId",
* description="Model ID",
* in="path",
* required=true,
* @OA\Schema(type="integer", example=1)
* ),
* @OA\Parameter(
* name="parameterId",
* description="Parameter ID",
* in="path",
* required=true,
* @OA\Schema(type="integer", example=1)
* ),
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(ref="#/components/schemas/UpdateModelParameterRequest")
* ),
* @OA\Response(
* response=200,
* description="Model parameter updated successfully",
* @OA\JsonContent(
* allOf={
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
* @OA\Schema(
* @OA\Property(property="data", ref="#/components/schemas/ModelParameterResource")
* )
* }
* )
* ),
* @OA\Response(ref="#/components/responses/ValidationErrorResponse", response=422),
* @OA\Response(ref="#/components/responses/ErrorResponse", response=400),
* @OA\Response(ref="#/components/responses/UnauthorizedResponse", response=401),
* @OA\Response(ref="#/components/responses/NotFoundResponse", response=404)
* )
*/
public function update(ModelParameterFormRequest $request, int $modelId, int $parameterId)
{
return ApiResponse::handle(function () use ($request, $modelId, $parameterId) {
return $this->service->updateParameter($modelId, $parameterId, $request->validated());
}, __('message.updated'));
}
/**
* @OA\Delete(
* path="/v1/design/models/{modelId}/parameters/{parameterId}",
* summary="Delete model parameter",
* description="Delete a specific model parameter",
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
* tags={"Model Parameters"},
* @OA\Parameter(
* name="modelId",
* description="Model ID",
* in="path",
* required=true,
* @OA\Schema(type="integer", example=1)
* ),
* @OA\Parameter(
* name="parameterId",
* description="Parameter ID",
* in="path",
* required=true,
* @OA\Schema(type="integer", example=1)
* ),
* @OA\Response(
* response=200,
* description="Model parameter deleted successfully",
* @OA\JsonContent(ref="#/components/schemas/ApiResponse")
* ),
* @OA\Response(ref="#/components/responses/ErrorResponse", response=400),
* @OA\Response(ref="#/components/responses/UnauthorizedResponse", response=401),
* @OA\Response(ref="#/components/responses/NotFoundResponse", response=404)
* )
*/
public function destroy(int $modelId, int $parameterId)
{
return ApiResponse::handle(function () use ($modelId, $parameterId) {
$this->service->deleteParameter($modelId, $parameterId);
return null;
}, __('message.deleted'));
}
}