feat: Items API item_type 기반 통합 조회/삭제 개선

- ItemTypeHelper를 활용한 item_type(FG/PT/SM/RM/CS) → source_table 매핑
- getItem: item_type 파라미터로 products/materials 테이블 자동 결정
- deleteItem: item_type 필수 파라미터 추가
- batchDeleteItems: item_type별 일괄 삭제 지원
- 목록 조회 시 attributes 플랫 전개
- Swagger 문서 업데이트
This commit is contained in:
2025-12-09 21:51:46 +09:00
parent 9d5f0ba4ca
commit cde89b2fb3
7 changed files with 367 additions and 93 deletions

View File

@@ -3,19 +3,21 @@
namespace App\Swagger\v1;
/**
* @OA\Tag(name="Items", description="품목 관리 (Product CRUD)")
* @OA\Tag(name="Items", description="품목 관리 (Product + Material CRUD)")
*
* @OA\Schema(
* schema="Item",
* type="object",
* required={"id","code","name","product_type","unit"},
* required={"id","code","name","item_type","unit"},
*
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="code", type="string", example="P-001"),
* @OA\Property(property="name", type="string", example="스크린 제품 A"),
* @OA\Property(property="product_type", type="string", example="FG", description="FG,PT,SM,RM,CS"),
* @OA\Property(property="item_type", type="string", example="FG", description="품목 유형 (FG|PT|SM|RM|CS)"),
* @OA\Property(property="type_code", type="string", example="FG", description="품목 유형 코드"),
* @OA\Property(property="unit", type="string", example="EA"),
* @OA\Property(property="category_id", type="integer", nullable=true, example=1),
* @OA\Property(property="specification", type="string", nullable=true, example="1.2T x 1219 x 2438", description="규격 (Material 전용)"),
* @OA\Property(property="description", type="string", nullable=true, example="제품 설명"),
* @OA\Property(property="is_sellable", type="boolean", example=true),
* @OA\Property(property="is_purchasable", type="boolean", example=false),
@@ -25,13 +27,10 @@
* @OA\Property(property="is_variable_size", type="boolean", example=false),
* @OA\Property(property="product_category", type="string", nullable=true, example="SCREEN"),
* @OA\Property(property="part_type", type="string", nullable=true, example="ASSEMBLY"),
* @OA\Property(
* property="attributes",
* type="object",
* nullable=true,
* description="동적 속성 (JSON)",
* example={"color": "black", "weight": 5.5}
* ),
* @OA\Property(property="item_name", type="string", nullable=true, example="철판", description="품명 (Material 전용)"),
* @OA\Property(property="is_inspection", type="string", nullable=true, example="Y", description="검수 여부 (Material 전용)"),
* @OA\Property(property="search_tag", type="string", nullable=true, example="철판,원자재,1.2T", description="검색 태그 (Material 전용)"),
* @OA\Property(property="remarks", type="string", nullable=true, example="비고", description="비고 (Material 전용)"),
* @OA\Property(property="created_at", type="string", example="2025-11-14 10:00:00"),
* @OA\Property(property="updated_at", type="string", example="2025-11-14 10:10:00"),
* @OA\Property(property="deleted_at", type="string", nullable=true, example=null, description="삭제일시 (soft delete)")
@@ -44,7 +43,7 @@
*
* @OA\Property(property="code", type="string", maxLength=50, example="P-001"),
* @OA\Property(property="name", type="string", maxLength=255, example="스크린 제품 A"),
* @OA\Property(property="product_type", type="string", example="FG", description="FG,PT,SM,RM,CS"),
* @OA\Property(property="product_type", type="string", example="FG", description="품목 유형 (FG|PT|SM|RM|CS)"),
* @OA\Property(property="unit", type="string", maxLength=20, example="EA"),
* @OA\Property(property="category_id", type="integer", nullable=true, example=1),
* @OA\Property(property="description", type="string", nullable=true, example="제품 설명"),
@@ -56,21 +55,25 @@
* @OA\Property(property="is_variable_size", type="boolean", nullable=true, example=false),
* @OA\Property(property="product_category", type="string", nullable=true, example="SCREEN"),
* @OA\Property(property="part_type", type="string", nullable=true, example="ASSEMBLY"),
* @OA\Property(
* property="attributes",
* type="object",
* nullable=true,
* description="동적 속성 (JSON)"
* )
* @OA\Property(property="attributes", type="object", nullable=true, description="동적 속성 (JSON)"),
* @OA\Property(property="material_code", type="string", nullable=true, maxLength=50, example="M-001", description="Material 코드 (Material 전용)"),
* @OA\Property(property="item_name", type="string", nullable=true, maxLength=255, example="철판", description="품명 (Material 전용)"),
* @OA\Property(property="specification", type="string", nullable=true, maxLength=255, example="1.2T x 1219 x 2438", description="규격 (Material 전용)"),
* @OA\Property(property="is_inspection", type="string", nullable=true, example="Y", description="검수 여부 Y|N (Material 전용)"),
* @OA\Property(property="search_tag", type="string", nullable=true, maxLength=255, example="철판,원자재", description="검색 태그 (Material 전용)"),
* @OA\Property(property="remarks", type="string", nullable=true, example="비고", description="비고 (Material 전용)"),
* @OA\Property(property="options", type="object", nullable=true, description="옵션 (Material 전용)")
* )
*
* @OA\Schema(
* schema="ItemUpdateRequest",
* type="object",
* required={"item_type"},
*
* @OA\Property(property="item_type", type="string", example="FG", description="품목 유형 (필수, FG|PT|SM|RM|CS)"),
* @OA\Property(property="code", type="string", maxLength=50, example="P-001"),
* @OA\Property(property="name", type="string", maxLength=255, example="스크린 제품 A"),
* @OA\Property(property="product_type", type="string", example="FG", description="FG,PT,SM,RM,CS"),
* @OA\Property(property="product_type", type="string", example="FG", description="FG|PT|SM|RM|CS"),
* @OA\Property(property="unit", type="string", maxLength=20, example="EA"),
* @OA\Property(property="category_id", type="integer", nullable=true, example=1),
* @OA\Property(property="description", type="string", nullable=true, example="제품 설명"),
@@ -82,19 +85,22 @@
* @OA\Property(property="is_variable_size", type="boolean", nullable=true, example=false),
* @OA\Property(property="product_category", type="string", nullable=true, example="SCREEN"),
* @OA\Property(property="part_type", type="string", nullable=true, example="ASSEMBLY"),
* @OA\Property(
* property="attributes",
* type="object",
* nullable=true,
* description="동적 속성 (JSON)"
* )
* @OA\Property(property="attributes", type="object", nullable=true, description="동적 속성 (JSON)"),
* @OA\Property(property="material_code", type="string", nullable=true, maxLength=50, example="M-001", description="Material 코드 (Material 전용)"),
* @OA\Property(property="item_name", type="string", nullable=true, maxLength=255, example="철판", description="품명 (Material 전용)"),
* @OA\Property(property="specification", type="string", nullable=true, maxLength=255, example="1.2T x 1219 x 2438", description="규격 (Material 전용)"),
* @OA\Property(property="is_inspection", type="string", nullable=true, example="Y", description="검수 여부 Y|N (Material 전용)"),
* @OA\Property(property="search_tag", type="string", nullable=true, maxLength=255, example="철판,원자재", description="검색 태그 (Material 전용)"),
* @OA\Property(property="remarks", type="string", nullable=true, example="비고", description="비고 (Material 전용)"),
* @OA\Property(property="options", type="object", nullable=true, description="옵션 (Material 전용)")
* )
*
* @OA\Schema(
* schema="ItemBatchDeleteRequest",
* type="object",
* required={"ids"},
* required={"item_type","ids"},
*
* @OA\Property(property="item_type", type="string", example="FG", description="품목 유형 (필수, FG|PT|SM|RM|CS)"),
* @OA\Property(
* property="ids",
* type="array",
@@ -112,7 +118,7 @@ class ItemsApi
* path="/api/v1/items",
* tags={"Items"},
* summary="품목 목록 조회 (통합)",
* description="Product + Material 통합 조회, 페이징 지원",
* description="Product + Material 통합 조회, 페이징 지원. attributes 필드는 플랫 전개됩니다.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\Parameter(ref="#/components/parameters/Page"),
@@ -130,7 +136,7 @@ class ItemsApi
* type="object",
*
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="품목 목록을 조회했습니다."),
* @OA\Property(property="message", type="string", example="조회되었습니다."),
* @OA\Property(property="data", type="array", @OA\Items(ref="#/components/schemas/Item")),
* @OA\Property(property="meta", ref="#/components/schemas/PaginationMeta")
* )
@@ -147,6 +153,7 @@ public function index() {}
* path="/api/v1/items",
* tags={"Items"},
* summary="품목 생성",
* description="product_type에 따라 Product(FG,PT) 또는 Material(SM,RM,CS) 테이블에 저장됩니다.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\RequestBody(
@@ -176,10 +183,11 @@ public function store() {}
* path="/api/v1/items/code/{code}",
* tags={"Items"},
* summary="품목 코드로 상세 조회",
* description="Product 먼저 조회 후, 없으면 Material에서 조회합니다.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\Parameter(name="code", in="path", required=true, @OA\Schema(type="string"), example="P-001"),
* @OA\Parameter(name="include_bom", in="query", @OA\Schema(type="boolean"), example=false),
* @OA\Parameter(name="include_bom", in="query", @OA\Schema(type="boolean"), example=false, description="BOM 포함 여부 (Product만 해당)"),
*
* @OA\Response(
* response=200,
@@ -192,7 +200,9 @@ public function store() {}
* @OA\Property(property="message", type="string", example="품목을 조회했습니다."),
* @OA\Property(property="data", ref="#/components/schemas/Item")
* )
* )
* ),
*
* @OA\Response(response=404, description="품목 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function showByCode() {}
@@ -202,11 +212,11 @@ public function showByCode() {}
* path="/api/v1/items/{id}",
* tags={"Items"},
* summary="품목 ID로 상세 조회",
* description="품목 ID로 상세 정보를 조회합니다. item_type 파라미터 필수.",
* description="item_type 파라미터로 조회할 테이블을 지정합니다. (FG,PT→products / SM,RM,CS→materials)",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer"), example=1, description="품목 ID"),
* @OA\Parameter(name="item_type", in="query", required=true, @OA\Schema(type="string", enum={"PRODUCT", "MATERIAL"}), example="PRODUCT", description="품목 유형"),
* @OA\Parameter(name="item_type", in="query", required=false, @OA\Schema(type="string", enum={"FG", "PT", "SM", "RM", "CS"}, default="FG"), example="FG", description="품목 유형 (기본값: FG)"),
* @OA\Parameter(name="include_price", in="query", @OA\Schema(type="boolean"), example=false, description="단가 정보 포함 여부"),
* @OA\Parameter(name="client_id", in="query", @OA\Schema(type="integer"), example=1, description="거래처 ID (단가 조회 시)"),
* @OA\Parameter(name="price_date", in="query", @OA\Schema(type="string", format="date"), example="2025-01-10", description="단가 기준일"),
@@ -222,7 +232,9 @@ public function showByCode() {}
* @OA\Property(property="message", type="string", example="조회되었습니다."),
* @OA\Property(property="data", ref="#/components/schemas/Item")
* )
* )
* ),
*
* @OA\Response(response=404, description="품목 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function show() {}
@@ -232,6 +244,7 @@ public function show() {}
* path="/api/v1/items/{id}",
* tags={"Items"},
* summary="품목 수정",
* description="item_type 필드 필수. Product(FG,PT) 또는 Material(SM,RM,CS)을 자동 분기하여 수정합니다.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer"), example=1, description="품목 ID"),
@@ -253,7 +266,10 @@ public function show() {}
* @OA\Property(property="message", type="string", example="품목이 수정되었습니다."),
* @OA\Property(property="data", ref="#/components/schemas/Item")
* )
* )
* ),
*
* @OA\Response(response=400, description="코드 중복", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="품목 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function update() {}
@@ -263,9 +279,11 @@ public function update() {}
* path="/api/v1/items/{id}",
* tags={"Items"},
* summary="품목 삭제",
* description="item_type 파라미터로 삭제할 테이블을 지정합니다. BOM 구성품으로 사용 중인 경우 삭제 불가.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\Parameter(name="id", in="path", required=true, @OA\Schema(type="integer"), example=1, description="품목 ID"),
* @OA\Parameter(name="item_type", in="query", required=false, @OA\Schema(type="string", enum={"FG", "PT", "SM", "RM", "CS"}, default="FG"), example="FG", description="품목 유형 (기본값: FG)"),
*
* @OA\Response(
* response=200,
@@ -278,7 +296,10 @@ public function update() {}
* @OA\Property(property="message", type="string", example="품목이 삭제되었습니다."),
* @OA\Property(property="data", type="string", example="success")
* )
* )
* ),
*
* @OA\Response(response=400, description="BOM 사용 중", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="품목 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function destroy() {}
@@ -288,7 +309,7 @@ public function destroy() {}
* path="/api/v1/items/batch",
* tags={"Items"},
* summary="품목 일괄 삭제",
* description="여러 품목을 한 번에 삭제합니다.",
* description="item_type 필드 필수. 여러 품목을 한 번에 삭제합니다. BOM 구성품으로 사용 중인 경우 삭제 불가.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\RequestBody(
@@ -308,7 +329,10 @@ public function destroy() {}
* @OA\Property(property="message", type="string", example="품목이 일괄 삭제되었습니다."),
* @OA\Property(property="data", type="string", example="success")
* )
* )
* ),
*
* @OA\Response(response=400, description="BOM 사용 중", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=404, description="품목 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function batchDestroy() {}