feat: Items API files 필드 추가 및 Swagger 문서 보완

- ItemService index에 files 관계 로드 추가
- files를 field_key별로 그룹화하여 응답 (bending_diagram, specification 등)
- Swagger에 group_id 파라미터 문서화
This commit is contained in:
2025-12-15 16:34:38 +09:00
parent c36f909728
commit f470978adb
2 changed files with 37 additions and 5 deletions

View File

@@ -313,11 +313,11 @@ public function index(array $params): LengthAwarePaginator
throw new BadRequestHttpException(__('error.invalid_group_id'));
}
$query = $this->newQueryForTypes($itemTypes)
->with(['category:id,name', 'details']);
->with(['category:id,name', 'details', 'files']);
} else {
// 단일 item_type 조회
$query = $this->newQuery($itemType)
->with(['category:id,name', 'details']);
->with(['category:id,name', 'details', 'files']);
}
// 검색어
@@ -341,7 +341,7 @@ public function index(array $params): LengthAwarePaginator
$paginator = $query->orderBy('id')->paginate($size);
// 날짜 형식 변환
// 날짜 형식 변환 및 files 그룹화
$paginator->setCollection(
$paginator->getCollection()->transform(function ($item) {
$arr = $item->toArray();
@@ -349,6 +349,9 @@ public function index(array $params): LengthAwarePaginator
? $item->created_at->format('Y-m-d')
: null;
// files를 field_key별로 그룹화
$arr['files'] = $this->groupFilesByFieldKey($arr['files'] ?? []);
return $arr;
})
);
@@ -744,4 +747,32 @@ private function extractDetailData(array $data): array
return array_intersect_key($data, array_flip($detailFields));
}
/**
* files 배열을 field_key별로 그룹화
*
* @param array $files 파일 배열
* @return array field_key별로 그룹화된 파일 배열
*/
private function groupFilesByFieldKey(array $files): array
{
if (empty($files)) {
return [];
}
$grouped = [];
foreach ($files as $file) {
$key = $file['field_key'] ?? 'default';
if (! isset($grouped[$key])) {
$grouped[$key] = [];
}
$grouped[$key][] = [
'id' => $file['id'],
'file_name' => $file['display_name'] ?? $file['original_name'] ?? $file['file_name'] ?? '',
'file_path' => $file['file_path'] ?? '',
];
}
return $grouped;
}
}

View File

@@ -130,13 +130,14 @@ class ItemsApi
* path="/api/v1/items",
* tags={"Items"},
* summary="품목 목록 조회 (통합)",
* description="Product + Material 통합 조회, 페이징 지원. attributes 필드는 플랫 전개됩니다.",
* 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 쉼표 구분)", example="FG,PT"),
* @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),
*