Files
sam-api/app/Http/Controllers/Api/V1/EstimateController.php
hskwon cc206fdbed style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수
- 302개 파일 스타일 이슈 자동 수정
- 코드 로직 변경 없음 (포맷팅만)
2025-11-06 17:45:49 +09:00

302 lines
10 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1;
use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Estimate\CreateEstimateRequest;
use App\Http\Requests\Estimate\UpdateEstimateRequest;
use App\Services\Estimate\EstimateService;
use Illuminate\Http\Request;
/**
* @OA\Tag(name="Estimate", description="견적 관리 API")
*/
class EstimateController extends Controller
{
protected EstimateService $estimateService;
public function __construct(EstimateService $estimateService)
{
$this->estimateService = $estimateService;
}
/**
* @OA\Get(
* path="/v1/estimates",
* summary="견적 목록 조회",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\Parameter(name="status", in="query", description="견적 상태", @OA\Schema(type="string")),
* @OA\Parameter(name="customer_name", in="query", description="고객명", @OA\Schema(type="string")),
* @OA\Parameter(name="model_set_id", in="query", description="모델셋 ID", @OA\Schema(type="integer")),
* @OA\Parameter(name="date_from", in="query", description="시작일", @OA\Schema(type="string", format="date")),
* @OA\Parameter(name="date_to", in="query", description="종료일", @OA\Schema(type="string", format="date")),
* @OA\Parameter(name="search", in="query", description="검색어", @OA\Schema(type="string")),
* @OA\Parameter(name="per_page", in="query", description="페이지당 항목수", @OA\Schema(type="integer", default=20)),
*
* @OA\Response(response=200, description="성공")
* )
*/
public function index(Request $request)
{
$estimates = $this->estimateService->getEstimates($request->all());
return ApiResponse::success([
'estimates' => $estimates,
], __('message.fetched'));
}
/**
* @OA\Get(
* path="/v1/estimates/{id}",
* summary="견적 상세 조회",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="견적 ID", @OA\Schema(type="integer")),
*
* @OA\Response(response=200, description="성공")
* )
*/
public function show($id)
{
$estimate = $this->estimateService->getEstimateDetail($id);
return ApiResponse::success([
'estimate' => $estimate,
], __('message.fetched'));
}
/**
* @OA\Post(
* path="/v1/estimates",
* summary="견적 생성",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(
* required={"model_set_id", "estimate_name", "parameters"},
*
* @OA\Property(property="model_set_id", type="integer", description="모델셋 ID"),
* @OA\Property(property="estimate_name", type="string", description="견적명"),
* @OA\Property(property="customer_name", type="string", description="고객명"),
* @OA\Property(property="project_name", type="string", description="프로젝트명"),
* @OA\Property(property="parameters", type="object", description="견적 파라미터"),
* @OA\Property(property="notes", type="string", description="비고")
* )
* ),
*
* @OA\Response(response=201, description="생성 성공")
* )
*/
public function store(CreateEstimateRequest $request)
{
$estimate = $this->estimateService->createEstimate($request->validated());
return ApiResponse::success([
'estimate' => $estimate,
], __('message.created'), 201);
}
/**
* @OA\Put(
* path="/v1/estimates/{id}",
* summary="견적 수정",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="견적 ID", @OA\Schema(type="integer")),
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(
*
* @OA\Property(property="estimate_name", type="string", description="견적명"),
* @OA\Property(property="customer_name", type="string", description="고객명"),
* @OA\Property(property="project_name", type="string", description="프로젝트명"),
* @OA\Property(property="parameters", type="object", description="견적 파라미터"),
* @OA\Property(property="status", type="string", description="견적 상태"),
* @OA\Property(property="notes", type="string", description="비고")
* )
* ),
*
* @OA\Response(response=200, description="수정 성공")
* )
*/
public function update(UpdateEstimateRequest $request, $id)
{
$estimate = $this->estimateService->updateEstimate($id, $request->validated());
return ApiResponse::success([
'estimate' => $estimate,
], __('message.updated'));
}
/**
* @OA\Delete(
* path="/v1/estimates/{id}",
* summary="견적 삭제",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="견적 ID", @OA\Schema(type="integer")),
*
* @OA\Response(response=200, description="삭제 성공")
* )
*/
public function destroy($id)
{
$this->estimateService->deleteEstimate($id);
return ApiResponse::success([], __('message.deleted'));
}
/**
* @OA\Post(
* path="/v1/estimates/{id}/clone",
* summary="견적 복제",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="견적 ID", @OA\Schema(type="integer")),
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(
* required={"estimate_name"},
*
* @OA\Property(property="estimate_name", type="string", description="새 견적명"),
* @OA\Property(property="customer_name", type="string", description="고객명"),
* @OA\Property(property="project_name", type="string", description="프로젝트명"),
* @OA\Property(property="notes", type="string", description="비고")
* )
* ),
*
* @OA\Response(response=201, description="복제 성공")
* )
*/
public function clone(Request $request, $id)
{
$request->validate([
'estimate_name' => 'required|string|max:255',
'customer_name' => 'nullable|string|max:255',
'project_name' => 'nullable|string|max:255',
'notes' => 'nullable|string|max:2000',
]);
$newEstimate = $this->estimateService->cloneEstimate($id, $request->all());
return ApiResponse::success([
'estimate' => $newEstimate,
], __('message.estimate.cloned'), 201);
}
/**
* @OA\Put(
* path="/v1/estimates/{id}/status",
* summary="견적 상태 변경",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, description="견적 ID", @OA\Schema(type="integer")),
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(
* required={"status"},
*
* @OA\Property(property="status", type="string", enum={"DRAFT","SENT","APPROVED","REJECTED","EXPIRED"}, description="변경할 상태"),
* @OA\Property(property="notes", type="string", description="상태 변경 사유")
* )
* ),
*
* @OA\Response(response=200, description="상태 변경 성공")
* )
*/
public function changeStatus(Request $request, $id)
{
$request->validate([
'status' => 'required|in:DRAFT,SENT,APPROVED,REJECTED,EXPIRED',
'notes' => 'nullable|string|max:1000',
]);
$estimate = $this->estimateService->changeEstimateStatus(
$id,
$request->status,
$request->notes
);
return ApiResponse::success([
'estimate' => $estimate,
], __('message.estimate.status_changed'));
}
/**
* @OA\Get(
* path="/v1/estimates/form-schema/{model_set_id}",
* summary="견적 폼 스키마 조회",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\Parameter(name="model_set_id", in="path", required=true, description="모델셋 ID", @OA\Schema(type="integer")),
*
* @OA\Response(response=200, description="성공")
* )
*/
public function getFormSchema($modelSetId)
{
$schema = $this->estimateService->getEstimateFormSchema($modelSetId);
return ApiResponse::success([
'form_schema' => $schema,
], __('message.fetched'));
}
/**
* @OA\Post(
* path="/v1/estimates/preview/{model_set_id}",
* summary="견적 계산 미리보기",
* tags={"Estimate"},
* security={{"bearerAuth": {}}},
*
* @OA\Parameter(name="model_set_id", in="path", required=true, description="모델셋 ID", @OA\Schema(type="integer")),
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(
* required={"parameters"},
*
* @OA\Property(property="parameters", type="object", description="견적 파라미터")
* )
* ),
*
* @OA\Response(response=200, description="계산 성공")
* )
*/
public function previewCalculation(Request $request, $modelSetId)
{
$request->validate([
'parameters' => 'required|array',
'parameters.*' => 'required',
]);
$calculation = $this->estimateService->previewCalculation(
$modelSetId,
$request->parameters
);
return ApiResponse::success([
'calculation' => $calculation,
], __('message.calculated'));
}
}