fix: 품목관리 API 응답 및 라우팅 오류 수정
- ItemsController: show/destroy 메서드 파라미터 타입 수정 (int → 동적 캐스팅) - ItemsController: store/update에서 product_type → item_type 변환 로직 추가 - ItemService: 정렬 순서 수정 (최신 품목이 먼저 표시되도록 desc 추가) - ItemService: code 키를 item_code로 변경 (ApiResponse::handle의 HTTP 상태 코드 충돌 방지) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -403,9 +403,9 @@ public function index(array $params): LengthAwarePaginator
|
||||
$query->where('is_active', (bool) $active);
|
||||
}
|
||||
|
||||
$paginator = $query->orderBy('id')->paginate($size);
|
||||
$paginator = $query->orderBy('id', 'desc')->paginate($size);
|
||||
|
||||
// 날짜 형식 변환, files 그룹화, options 펼침
|
||||
// 날짜 형식 변환, files 그룹화, options 펼침, code → item_code
|
||||
$paginator->setCollection(
|
||||
$paginator->getCollection()->transform(function ($item) {
|
||||
$arr = $item->toArray();
|
||||
@@ -419,6 +419,12 @@ public function index(array $params): LengthAwarePaginator
|
||||
// options를 최상위 레벨로 펼침 (동적 필드)
|
||||
$arr = $this->flattenOptionsToResponse($arr);
|
||||
|
||||
// 'code' 키를 'item_code'로 변경 (ApiResponse::handle의 HTTP 상태 코드 충돌 방지)
|
||||
if (isset($arr['code'])) {
|
||||
$arr['item_code'] = $arr['code'];
|
||||
unset($arr['code']);
|
||||
}
|
||||
|
||||
return $arr;
|
||||
})
|
||||
);
|
||||
@@ -553,6 +559,12 @@ private function formatItemResponse(Model $item): array
|
||||
// options를 최상위 레벨로 펼침 (동적 필드)
|
||||
$arr = $this->flattenOptionsToResponse($arr);
|
||||
|
||||
// 'code' 키를 'item_code'로 변경 (ApiResponse::handle의 HTTP 상태 코드 충돌 방지)
|
||||
if (isset($arr['code'])) {
|
||||
$arr['item_code'] = $arr['code'];
|
||||
unset($arr['code']);
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user