feat: 견적 시스템 API
- 5130의 71개 하드코딩 컬럼을 동적 카테고리 필드 시스템으로 전환 - 모터 브라켓 계산 등 핵심 비즈니스 로직 FormulaParser에 통합 - 파라미터 기반 동적 견적 폼 시스템 구축 - 견적 상태 워크플로 (DRAFT → SENT → APPROVED/REJECTED/EXPIRED) - 모델셋 관리 API: 카테고리+제품+BOM 통합 관리 - 견적 관리 API: 생성/수정/복제/상태변경/미리보기 기능 주요 구현 사항: - EstimateController/EstimateService: 견적 비즈니스 로직 - ModelSetController/ModelSetService: 모델셋 관리 로직 - Estimate/EstimateItem 모델: 견적 데이터 구조 - 동적 견적 필드 마이그레이션: 스크린/철재 제품 구조 - API 라우트 17개 엔드포인트 추가 - 다국어 메시지 지원 (성공/에러 메시지) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
269
app/Http/Controllers/Api/V1/EstimateController.php
Normal file
269
app/Http/Controllers/Api/V1/EstimateController.php
Normal file
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Estimate\CreateEstimateRequest;
|
||||
use App\Http\Requests\Estimate\UpdateEstimateRequest;
|
||||
use App\Services\Estimate\EstimateService;
|
||||
use App\Helpers\ApiResponse;
|
||||
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'));
|
||||
}
|
||||
}
|
||||
137
app/Http/Controllers/Api/V1/ModelSetController.php
Normal file
137
app/Http/Controllers/Api/V1/ModelSetController.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ModelSet\CreateModelSetRequest;
|
||||
use App\Http\Requests\ModelSet\UpdateModelSetRequest;
|
||||
use App\Http\Requests\ModelSet\CloneModelSetRequest;
|
||||
use App\Services\ModelSet\ModelSetService;
|
||||
use App\Helpers\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModelSetController extends Controller
|
||||
{
|
||||
protected ModelSetService $modelSetService;
|
||||
|
||||
public function __construct(ModelSetService $modelSetService)
|
||||
{
|
||||
$this->modelSetService = $modelSetService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋 목록 조회
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$modelSets = $this->modelSetService->getModelSets($request->validated());
|
||||
|
||||
return ApiResponse::success([
|
||||
'model_sets' => $modelSets
|
||||
], __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋 상세 조회
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$modelSet = $this->modelSetService->getModelSetDetail($id);
|
||||
|
||||
return ApiResponse::success([
|
||||
'model_set' => $modelSet
|
||||
], __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 새로운 모델셋 생성
|
||||
*/
|
||||
public function store(CreateModelSetRequest $request)
|
||||
{
|
||||
$modelSet = $this->modelSetService->createModelSet($request->validated());
|
||||
|
||||
return ApiResponse::success([
|
||||
'model_set' => $modelSet
|
||||
], __('message.created'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋 수정
|
||||
*/
|
||||
public function update(UpdateModelSetRequest $request, $id)
|
||||
{
|
||||
$modelSet = $this->modelSetService->updateModelSet($id, $request->validated());
|
||||
|
||||
return ApiResponse::success([
|
||||
'model_set' => $modelSet
|
||||
], __('message.updated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋 삭제
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->modelSetService->deleteModelSet($id);
|
||||
|
||||
return ApiResponse::success([], __('message.deleted'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋 복제
|
||||
*/
|
||||
public function clone(CloneModelSetRequest $request, $id)
|
||||
{
|
||||
$newModelSet = $this->modelSetService->cloneModelSet($id, $request->validated());
|
||||
|
||||
return ApiResponse::success([
|
||||
'model_set' => $newModelSet
|
||||
], __('message.model_set.cloned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋의 카테고리별 필드 구조 조회
|
||||
*/
|
||||
public function getCategoryFields($id)
|
||||
{
|
||||
$fields = $this->modelSetService->getModelSetCategoryFields($id);
|
||||
|
||||
return ApiResponse::success([
|
||||
'category_fields' => $fields
|
||||
], __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋의 BOM 템플릿 목록
|
||||
*/
|
||||
public function getBomTemplates($id)
|
||||
{
|
||||
$templates = $this->modelSetService->getModelSetBomTemplates($id);
|
||||
|
||||
return ApiResponse::success([
|
||||
'bom_templates' => $templates
|
||||
], __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋 기반 견적 파라미터 조회
|
||||
*/
|
||||
public function getEstimateParameters($id, Request $request)
|
||||
{
|
||||
$parameters = $this->modelSetService->getEstimateParameters($id, $request->all());
|
||||
|
||||
return ApiResponse::success([
|
||||
'parameters' => $parameters
|
||||
], __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델셋 기반 BOM 계산
|
||||
*/
|
||||
public function calculateBom($id, Request $request)
|
||||
{
|
||||
$result = $this->modelSetService->calculateModelSetBom($id, $request->all());
|
||||
|
||||
return ApiResponse::success($result, __('message.calculated'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user