fix: Items API 유연성 개선 - Flow Tester 호환성

- GET /api/v1/items/bom 엔드포인트 추가 (BOM 있는 전체 품목 목록)
- ItemService::index() item_type/group_id 없으면 group_id=1 기본값 적용
- ItemService::showByCode() item_type 없으면 items 테이블에서 직접 검색
- ItemsBomController::listAll() 메서드 추가

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-21 16:06:13 +09:00
parent 756d08be09
commit 3e31c8da22
3 changed files with 69 additions and 4 deletions

View File

@@ -344,7 +344,7 @@ protected function fetchCategoryTree(?int $parentId = null)
/**
* 목록/검색 (동적 테이블 라우팅)
*
* @param array $params 검색 파라미터 (item_type 또는 group_id 필수)
* @param array $params 검색 파라미터 (item_type/group_id 없으면 group_id=1 기본값)
*/
public function index(array $params): LengthAwarePaginator
{
@@ -355,9 +355,9 @@ public function index(array $params): LengthAwarePaginator
$groupId = $params['group_id'] ?? null;
$active = $params['active'] ?? null;
// item_type 또는 group_id 필수 검증
// item_type 또는 group_id 없으면 group_id = 1 기본값 적용
if (! $itemType && ! $groupId) {
throw new BadRequestHttpException(__('error.item_type_or_group_required'));
$groupId = 1;
}
// group_id로 조회 시 해당 그룹의 모든 item_type 조회
@@ -778,11 +778,29 @@ public function toggle(int $id, string $itemType): array
* code 기반 품목 조회 (동적 테이블 라우팅, BOM 포함 옵션)
*
* @param string $code 품목 코드
* @param string $itemType 품목 유형 (필수)
* @param string $itemType 품목 유형 (없으면 items 테이블에서 직접 검색)
* @param bool $includeBom BOM 포함 여부
*/
public function showByCode(string $code, string $itemType, bool $includeBom = false): Model
{
// item_type 없으면 items 테이블에서 직접 검색
if (empty($itemType)) {
$item = Item::where('tenant_id', $this->tenantId())
->where('code', $code)
->with(['category:id,name', 'details'])
->first();
if (! $item) {
throw new BadRequestHttpException(__('error.not_found'));
}
if ($includeBom && ! empty($item->bom) && method_exists($item, 'loadBomChildren')) {
$item->loadBomChildren();
}
return $item;
}
// 동적 테이블 라우팅
$modelInfo = $this->getModelInfoByItemType($itemType);
$query = $this->newQuery($itemType)->where('code', $code);