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:
@@ -16,6 +16,49 @@
|
||||
*/
|
||||
class ItemsBomController extends Controller
|
||||
{
|
||||
/**
|
||||
* GET /api/v1/items/bom
|
||||
* BOM이 있는 전체 품목 목록 조회 (item_id 없이)
|
||||
*/
|
||||
public function listAll(Request $request)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request) {
|
||||
$tenantId = app('tenant_id');
|
||||
$perPage = (int) ($request->input('per_page', $request->input('size', 20)));
|
||||
$itemType = $request->input('item_type');
|
||||
|
||||
$query = Item::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->whereNotNull('bom')
|
||||
->where('bom', '!=', '[]')
|
||||
->where('bom', '!=', 'null');
|
||||
|
||||
// item_type 필터 (선택)
|
||||
if ($itemType) {
|
||||
$query->where('item_type', strtoupper($itemType));
|
||||
}
|
||||
|
||||
$items = $query->orderBy('id')
|
||||
->paginate($perPage, ['id', 'code', 'name', 'item_type', 'unit', 'bom']);
|
||||
|
||||
// BOM 개수 추가
|
||||
$items->getCollection()->transform(function ($item) {
|
||||
$bom = $item->bom ?? [];
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'code' => $item->code,
|
||||
'name' => $item->name,
|
||||
'item_type' => $item->item_type,
|
||||
'unit' => $item->unit,
|
||||
'bom_count' => count($bom),
|
||||
'bom' => $this->expandBomItems($bom),
|
||||
];
|
||||
});
|
||||
|
||||
return $items;
|
||||
}, __('message.bom.fetch'));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/items/{id}/bom
|
||||
* BOM 라인 목록 조회 (flat list)
|
||||
|
||||
Reference in New Issue
Block a user