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

@@ -33,17 +33,17 @@ public function index(Request $request)
/**
* 단일 품목 조회
*
* GET /api/v1/items/{id}?item_type=PRODUCT|MATERIAL&include_price=true&client_id=1&price_date=2025-01-10
* GET /api/v1/items/{id}?item_type=FG|PT|SM|RM|CS&include_price=true&client_id=1&price_date=2025-01-10
*/
public function show(Request $request, int $id)
{
return ApiResponse::handle(function () use ($request, $id) {
$itemType = strtoupper($request->input('item_type', 'PRODUCT'));
$itemType = strtoupper($request->input('item_type', 'FG'));
$includePrice = filter_var($request->input('include_price', false), FILTER_VALIDATE_BOOLEAN);
$clientId = $request->input('client_id') ? (int) $request->input('client_id') : null;
$priceDate = $request->input('price_date');
return $this->service->getItem($itemType, $id, $includePrice, $clientId, $priceDate);
return $this->service->getItem($id, $itemType, $includePrice, $clientId, $priceDate);
}, __('message.fetched'));
}
@@ -88,12 +88,13 @@ public function update(int $id, ItemUpdateRequest $request)
/**
* 품목 삭제 (Soft Delete)
*
* DELETE /api/v1/items/{id}
* DELETE /api/v1/items/{id}?item_type=FG|PT|SM|RM|CS
*/
public function destroy(int $id)
public function destroy(Request $request, int $id)
{
return ApiResponse::handle(function () use ($id) {
$this->service->deleteItem($id);
return ApiResponse::handle(function () use ($request, $id) {
$itemType = strtoupper($request->input('item_type', 'FG'));
$this->service->deleteItem($id, $itemType);
return 'success';
}, __('message.item.deleted'));
@@ -107,7 +108,9 @@ public function destroy(int $id)
public function batchDestroy(ItemBatchDeleteRequest $request)
{
return ApiResponse::handle(function () use ($request) {
$this->service->batchDeleteItems($request->validated()['ids']);
$validated = $request->validated();
$itemType = strtoupper($validated['item_type'] ?? 'FG');
$this->service->batchDeleteItems($validated['ids'], $itemType);
return 'success';
}, __('message.item.batch_deleted'));

View File

@@ -14,6 +14,7 @@ public function authorize(): bool
public function rules(): array
{
return [
'item_type' => 'required|string|in:FG,PT,SM,RM,CS',
'ids' => 'required|array|min:1',
'ids.*' => 'required|integer|min:1',
];
@@ -22,6 +23,8 @@ public function rules(): array
public function messages(): array
{
return [
'item_type.required' => '품목 유형은 필수입니다.',
'item_type.in' => '품목 유형은 FG, PT, SM, RM, CS 중 하나여야 합니다.',
'ids.required' => '삭제할 품목 ID 목록은 필수입니다.',
'ids.array' => '품목 ID 목록은 배열이어야 합니다.',
'ids.min' => '삭제할 품목을 하나 이상 선택하세요.',

View File

@@ -38,6 +38,15 @@ public function rules(): array
// 동적 필드 (JSON)
'attributes' => 'nullable|array',
// Material 전용 필드
'material_code' => 'nullable|string|max:50',
'item_name' => 'nullable|string|max:255',
'specification' => 'nullable|string|max:255',
'is_inspection' => 'nullable|string|in:Y,N',
'search_tag' => 'nullable|string|max:255',
'remarks' => 'nullable|string',
'options' => 'nullable|array',
];
}

View File

@@ -14,6 +14,9 @@ public function authorize(): bool
public function rules(): array
{
return [
// 품목 유형 (필수 - 테이블 분기용)
'item_type' => 'required|string|in:FG,PT,SM,RM,CS',
// 선택 필드 (모두 sometimes)
'code' => 'sometimes|string|max:50',
'name' => 'sometimes|string|max:255',
@@ -36,12 +39,23 @@ public function rules(): array
// 동적 필드 (JSON)
'attributes' => 'sometimes|array',
// Material 전용 필드
'material_code' => 'sometimes|string|max:50',
'item_name' => 'nullable|string|max:255',
'specification' => 'nullable|string|max:255',
'is_inspection' => 'nullable|string|in:Y,N',
'search_tag' => 'nullable|string|max:255',
'remarks' => 'nullable|string',
'options' => 'nullable|array',
];
}
public function messages(): array
{
return [
'item_type.required' => '품목 유형은 필수입니다.',
'item_type.in' => '품목 유형은 FG, PT, SM, RM, CS 중 하나여야 합니다.',
'code.max' => '품목코드는 50자 이내로 입력하세요.',
'name.max' => '품목명은 255자 이내로 입력하세요.',
'product_type.in' => '품목 유형은 FG, PT, SM, RM, CS 중 하나여야 합니다.',