278 lines
11 KiB
PHP
278 lines
11 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Api\V1\Design;
|
||
|
|
|
||
|
|
use App\Helpers\ApiResponse;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Services\ModelFormulaService;
|
||
|
|
use App\Http\Requests\Api\V1\Design\ModelFormulaFormRequest;
|
||
|
|
use App\Http\Requests\Api\V1\ModelFormula\IndexModelFormulaRequest;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Tag(name="Model Formulas", description="Model formula management APIs")
|
||
|
|
*/
|
||
|
|
class ModelFormulaController extends Controller
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
protected ModelFormulaService $service
|
||
|
|
) {}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Get(
|
||
|
|
* path="/v1/design/models/{modelId}/formulas",
|
||
|
|
* summary="Get model formulas",
|
||
|
|
* description="Retrieve all formulas for a specific model",
|
||
|
|
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
|
||
|
|
* tags={"Model Formulas"},
|
||
|
|
* @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 formula name or target parameter",
|
||
|
|
* in="query",
|
||
|
|
* required=false,
|
||
|
|
* @OA\Schema(type="string", example="calculate_area")
|
||
|
|
* ),
|
||
|
|
* @OA\Response(
|
||
|
|
* response=200,
|
||
|
|
* description="Model formulas 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/ModelFormulaResource")
|
||
|
|
* ),
|
||
|
|
* @OA\Property(property="current_page", type="integer", example=1),
|
||
|
|
* @OA\Property(property="last_page", type="integer", example=2),
|
||
|
|
* @OA\Property(property="per_page", type="integer", example=20),
|
||
|
|
* @OA\Property(property="total", type="integer", example=25)
|
||
|
|
* )
|
||
|
|
* )
|
||
|
|
* }
|
||
|
|
* )
|
||
|
|
* ),
|
||
|
|
* @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(IndexModelFormulaRequest $request, int $modelId)
|
||
|
|
{
|
||
|
|
return ApiResponse::handle(function () use ($request, $modelId) {
|
||
|
|
return $this->service->getModelFormulas($modelId, $request->validated());
|
||
|
|
}, __('message.fetched'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Post(
|
||
|
|
* path="/v1/design/models/{modelId}/formulas",
|
||
|
|
* summary="Create model formula",
|
||
|
|
* description="Create a new formula for a specific model",
|
||
|
|
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
|
||
|
|
* tags={"Model Formulas"},
|
||
|
|
* @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/CreateModelFormulaRequest")
|
||
|
|
* ),
|
||
|
|
* @OA\Response(
|
||
|
|
* response=201,
|
||
|
|
* description="Model formula created successfully",
|
||
|
|
* @OA\JsonContent(
|
||
|
|
* allOf={
|
||
|
|
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||
|
|
* @OA\Schema(
|
||
|
|
* @OA\Property(property="data", ref="#/components/schemas/ModelFormulaResource")
|
||
|
|
* )
|
||
|
|
* }
|
||
|
|
* )
|
||
|
|
* ),
|
||
|
|
* @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(ModelFormulaFormRequest $request, int $modelId)
|
||
|
|
{
|
||
|
|
return ApiResponse::handle(function () use ($request, $modelId) {
|
||
|
|
return $this->service->createFormula($modelId, $request->validated());
|
||
|
|
}, __('message.created'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Put(
|
||
|
|
* path="/v1/design/models/{modelId}/formulas/{formulaId}",
|
||
|
|
* summary="Update model formula",
|
||
|
|
* description="Update a specific model formula",
|
||
|
|
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
|
||
|
|
* tags={"Model Formulas"},
|
||
|
|
* @OA\Parameter(
|
||
|
|
* name="modelId",
|
||
|
|
* description="Model ID",
|
||
|
|
* in="path",
|
||
|
|
* required=true,
|
||
|
|
* @OA\Schema(type="integer", example=1)
|
||
|
|
* ),
|
||
|
|
* @OA\Parameter(
|
||
|
|
* name="formulaId",
|
||
|
|
* description="Formula ID",
|
||
|
|
* in="path",
|
||
|
|
* required=true,
|
||
|
|
* @OA\Schema(type="integer", example=1)
|
||
|
|
* ),
|
||
|
|
* @OA\RequestBody(
|
||
|
|
* required=true,
|
||
|
|
* @OA\JsonContent(ref="#/components/schemas/UpdateModelFormulaRequest")
|
||
|
|
* ),
|
||
|
|
* @OA\Response(
|
||
|
|
* response=200,
|
||
|
|
* description="Model formula updated successfully",
|
||
|
|
* @OA\JsonContent(
|
||
|
|
* allOf={
|
||
|
|
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||
|
|
* @OA\Schema(
|
||
|
|
* @OA\Property(property="data", ref="#/components/schemas/ModelFormulaResource")
|
||
|
|
* )
|
||
|
|
* }
|
||
|
|
* )
|
||
|
|
* ),
|
||
|
|
* @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(ModelFormulaFormRequest $request, int $modelId, int $formulaId)
|
||
|
|
{
|
||
|
|
return ApiResponse::handle(function () use ($request, $modelId, $formulaId) {
|
||
|
|
return $this->service->updateFormula($modelId, $formulaId, $request->validated());
|
||
|
|
}, __('message.updated'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Delete(
|
||
|
|
* path="/v1/design/models/{modelId}/formulas/{formulaId}",
|
||
|
|
* summary="Delete model formula",
|
||
|
|
* description="Delete a specific model formula",
|
||
|
|
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
|
||
|
|
* tags={"Model Formulas"},
|
||
|
|
* @OA\Parameter(
|
||
|
|
* name="modelId",
|
||
|
|
* description="Model ID",
|
||
|
|
* in="path",
|
||
|
|
* required=true,
|
||
|
|
* @OA\Schema(type="integer", example=1)
|
||
|
|
* ),
|
||
|
|
* @OA\Parameter(
|
||
|
|
* name="formulaId",
|
||
|
|
* description="Formula ID",
|
||
|
|
* in="path",
|
||
|
|
* required=true,
|
||
|
|
* @OA\Schema(type="integer", example=1)
|
||
|
|
* ),
|
||
|
|
* @OA\Response(
|
||
|
|
* response=200,
|
||
|
|
* description="Model formula 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 $formulaId)
|
||
|
|
{
|
||
|
|
return ApiResponse::handle(function () use ($modelId, $formulaId) {
|
||
|
|
$this->service->deleteFormula($modelId, $formulaId);
|
||
|
|
return null;
|
||
|
|
}, __('message.deleted'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @OA\Post(
|
||
|
|
* path="/v1/design/models/{modelId}/formulas/{formulaId}/validate",
|
||
|
|
* summary="Validate model formula",
|
||
|
|
* description="Validate formula expression and dependencies",
|
||
|
|
* security={{"ApiKeyAuth": {}}, {"BearerAuth": {}}},
|
||
|
|
* tags={"Model Formulas"},
|
||
|
|
* @OA\Parameter(
|
||
|
|
* name="modelId",
|
||
|
|
* description="Model ID",
|
||
|
|
* in="path",
|
||
|
|
* required=true,
|
||
|
|
* @OA\Schema(type="integer", example=1)
|
||
|
|
* ),
|
||
|
|
* @OA\Parameter(
|
||
|
|
* name="formulaId",
|
||
|
|
* description="Formula ID",
|
||
|
|
* in="path",
|
||
|
|
* required=true,
|
||
|
|
* @OA\Schema(type="integer", example=1)
|
||
|
|
* ),
|
||
|
|
* @OA\Response(
|
||
|
|
* response=200,
|
||
|
|
* description="Formula validation result",
|
||
|
|
* @OA\JsonContent(
|
||
|
|
* allOf={
|
||
|
|
* @OA\Schema(ref="#/components/schemas/ApiResponse"),
|
||
|
|
* @OA\Schema(
|
||
|
|
* @OA\Property(
|
||
|
|
* property="data",
|
||
|
|
* @OA\Property(property="is_valid", type="boolean", example=true),
|
||
|
|
* @OA\Property(
|
||
|
|
* property="validation_errors",
|
||
|
|
* type="array",
|
||
|
|
* @OA\Items(type="string", example="Unknown variable: unknown_var")
|
||
|
|
* ),
|
||
|
|
* @OA\Property(
|
||
|
|
* property="dependency_chain",
|
||
|
|
* type="array",
|
||
|
|
* @OA\Items(type="string", example="W0")
|
||
|
|
* )
|
||
|
|
* )
|
||
|
|
* )
|
||
|
|
* }
|
||
|
|
* )
|
||
|
|
* ),
|
||
|
|
* @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 validate(int $modelId, int $formulaId)
|
||
|
|
{
|
||
|
|
return ApiResponse::handle(function () use ($modelId, $formulaId) {
|
||
|
|
return $this->service->validateFormula($modelId, $formulaId);
|
||
|
|
}, __('message.formula.validated'));
|
||
|
|
}
|
||
|
|
}
|