Files
sam-api/app/Swagger/v1/ItemsApi.php
hskwon f470978adb feat: Items API files 필드 추가 및 Swagger 문서 보완
- ItemService index에 files 관계 로드 추가
- files를 field_key별로 그룹화하여 응답 (bending_diagram, specification 등)
- Swagger에 group_id 파라미터 문서화
2025-12-15 16:34:38 +09:00

353 lines
18 KiB
PHP

<?php
namespace App\Swagger\v1;
/**
* @OA\Tag(name="Items", description="품목 관리 (Product + Material CRUD)")
*
* @OA\Schema(
* schema="Item",
* type="object",
* 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="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),
* @OA\Property(property="is_producible", type="boolean", example=false),
* @OA\Property(property="safety_stock", type="integer", nullable=true, example=10),
* @OA\Property(property="lead_time", type="integer", nullable=true, example=7),
* @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="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)"),
* @OA\Property(
* property="files",
* type="object",
* nullable=true,
* description="첨부 파일 (field_key별 그룹핑)",
* example={"bending_diagram": {{"id": 1, "file_name": "벤딩도.pdf", "file_path": "/uploads/items/1/bending_diagram.pdf"}}, "specification": {{"id": 2, "file_name": "규격서.pdf", "file_path": "/uploads/items/1/specification.pdf"}}},
* additionalProperties=@OA\Property(
* type="array",
*
* @OA\Items(ref="#/components/schemas/ItemFile")
* )
* )
* )
*
* @OA\Schema(
* schema="ItemCreateRequest",
* type="object",
* required={"code","name","product_type","unit"},
*
* @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="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="제품 설명"),
* @OA\Property(property="is_sellable", type="boolean", nullable=true, example=true),
* @OA\Property(property="is_purchasable", type="boolean", nullable=true, example=false),
* @OA\Property(property="is_producible", type="boolean", nullable=true, example=false),
* @OA\Property(property="safety_stock", type="integer", nullable=true, example=10),
* @OA\Property(property="lead_time", type="integer", nullable=true, example=7),
* @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="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="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="제품 설명"),
* @OA\Property(property="is_sellable", type="boolean", nullable=true, example=true),
* @OA\Property(property="is_purchasable", type="boolean", nullable=true, example=false),
* @OA\Property(property="is_producible", type="boolean", nullable=true, example=false),
* @OA\Property(property="safety_stock", type="integer", nullable=true, example=10),
* @OA\Property(property="lead_time", type="integer", nullable=true, example=7),
* @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="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={"item_type","ids"},
*
* @OA\Property(property="item_type", type="string", example="FG", description="품목 유형 (필수, FG|PT|SM|RM|CS)"),
* @OA\Property(
* property="ids",
* type="array",
* description="삭제할 품목 ID 목록",
*
* @OA\Items(type="integer"),
* example={1, 2, 3}
* )
* )
*/
class ItemsApi
{
/**
* @OA\Get(
* path="/api/v1/items",
* tags={"Items"},
* summary="품목 목록 조회 (통합)",
* description="Product + Material 통합 조회, 페이징 지원. type 또는 group_id 중 하나는 필수입니다.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\Parameter(ref="#/components/parameters/Page"),
* @OA\Parameter(ref="#/components/parameters/Size"),
* @OA\Parameter(name="search", in="query", @OA\Schema(type="string"), description="검색어 (code, name)", example="P-001"),
* @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), description="품목 타입 (FG,PT,SM,RM,CS). type 또는 group_id 중 하나 필수", example="FG"),
* @OA\Parameter(name="group_id", in="query", @OA\Schema(type="integer"), description="그룹 ID (1=품목). type 또는 group_id 중 하나 필수", example=1),
* @OA\Parameter(name="category_id", in="query", @OA\Schema(type="integer"), description="카테고리 ID 필터", example=1),
* @OA\Parameter(name="include_deleted", in="query", @OA\Schema(type="boolean"), description="삭제된 항목 포함 여부", example=false),
*
* @OA\Response(
* response=200,
* description="성공",
*
* @OA\JsonContent(
* type="object",
*
* @OA\Property(property="success", type="boolean", example=true),
* @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")
* )
* ),
*
* @OA\Response(response=401, description="인증 실패", @OA\JsonContent(ref="#/components/schemas/ErrorResponse")),
* @OA\Response(response=403, description="권한 없음", @OA\JsonContent(ref="#/components/schemas/ErrorResponse"))
* )
*/
public function index() {}
/**
* @OA\Post(
* path="/api/v1/items",
* tags={"Items"},
* summary="품목 생성",
* description="product_type에 따라 Product(FG,PT) 또는 Material(SM,RM,CS) 테이블에 저장됩니다.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(ref="#/components/schemas/ItemCreateRequest")
* ),
*
* @OA\Response(
* response=200,
* description="성공",
*
* @OA\JsonContent(
* type="object",
*
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="품목이 등록되었습니다."),
* @OA\Property(property="data", ref="#/components/schemas/Item")
* )
* )
* )
*/
public function store() {}
/**
* @OA\Get(
* 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, description="BOM 포함 여부 (Product만 해당)"),
*
* @OA\Response(
* response=200,
* description="성공",
*
* @OA\JsonContent(
* type="object",
*
* @OA\Property(property="success", type="boolean", example=true),
* @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() {}
/**
* @OA\Get(
* path="/api/v1/items/{id}",
* tags={"Items"},
* summary="품목 ID로 상세 조회",
* 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=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="단가 기준일"),
*
* @OA\Response(
* response=200,
* description="성공",
*
* @OA\JsonContent(
* type="object",
*
* @OA\Property(property="success", type="boolean", example=true),
* @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() {}
/**
* @OA\Put(
* 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"),
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(ref="#/components/schemas/ItemUpdateRequest")
* ),
*
* @OA\Response(
* response=200,
* description="성공",
*
* @OA\JsonContent(
* type="object",
*
* @OA\Property(property="success", type="boolean", example=true),
* @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() {}
/**
* @OA\Delete(
* 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,
* description="성공",
*
* @OA\JsonContent(
* type="object",
*
* @OA\Property(property="success", type="boolean", example=true),
* @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() {}
/**
* @OA\Delete(
* path="/api/v1/items/batch",
* tags={"Items"},
* summary="품목 일괄 삭제",
* description="item_type 필드 필수. 여러 품목을 한 번에 삭제합니다. BOM 구성품으로 사용 중인 경우 삭제 불가.",
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(ref="#/components/schemas/ItemBatchDeleteRequest")
* ),
*
* @OA\Response(
* response=200,
* description="성공",
*
* @OA\JsonContent(
* type="object",
*
* @OA\Property(property="success", type="boolean", example=true),
* @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() {}
}