feat: Items Files API 개선 - group_id 기반, 동적 field_key 지원
- GET /items/{id}/files 엔드포인트 추가 (파일 목록 조회)
- document_type을 group_id('1')로 변경 (테이블명 대신 코드 기반)
- field_key 제한 해제 (자유롭게 지정 가능)
- 품목 상세 조회 시 files 필드 포함 (field_key별 그룹핑)
- ItemFileUploadRequest FormRequest 추가
- DELETE 라우트 파라미터를 {fileId}로 변경
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
use App\Constants\SystemFields;
|
||||
use App\Exceptions\DuplicateCodeException;
|
||||
use App\Helpers\ItemTypeHelper;
|
||||
use App\Models\Commons\File;
|
||||
use App\Models\ItemMaster\ItemField;
|
||||
use App\Models\Materials\Material;
|
||||
use App\Models\Products\Product;
|
||||
@@ -318,19 +319,19 @@ public function getItems(array $filters = [], int $perPage = 20, bool $includeDe
|
||||
}
|
||||
|
||||
$productsQuery->select([
|
||||
'id',
|
||||
'product_type as item_type',
|
||||
'code',
|
||||
'name',
|
||||
DB::raw('NULL as specification'),
|
||||
'unit',
|
||||
'category_id',
|
||||
'product_type as type_code',
|
||||
'attributes',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
]);
|
||||
'id',
|
||||
'product_type as item_type',
|
||||
'code',
|
||||
'name',
|
||||
DB::raw('NULL as specification'),
|
||||
'unit',
|
||||
'category_id',
|
||||
'product_type as type_code',
|
||||
'attributes',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
]);
|
||||
|
||||
// soft delete 포함
|
||||
if ($includeDeleted) {
|
||||
@@ -364,19 +365,19 @@ public function getItems(array $filters = [], int $perPage = 20, bool $includeDe
|
||||
}
|
||||
|
||||
$materialsQuery->select([
|
||||
'id',
|
||||
'material_type as item_type',
|
||||
'material_code as code',
|
||||
'name',
|
||||
'specification',
|
||||
'unit',
|
||||
'category_id',
|
||||
'material_type as type_code',
|
||||
'attributes',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
]);
|
||||
'id',
|
||||
'material_type as item_type',
|
||||
'material_code as code',
|
||||
'name',
|
||||
'specification',
|
||||
'unit',
|
||||
'category_id',
|
||||
'material_type as type_code',
|
||||
'attributes',
|
||||
'is_active',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
]);
|
||||
|
||||
// soft delete 포함
|
||||
if ($includeDeleted) {
|
||||
@@ -484,6 +485,9 @@ public function getItem(
|
||||
$data['prices'] = $this->fetchPrices('MATERIAL', $id, $clientId, $priceDate);
|
||||
}
|
||||
|
||||
// 파일 정보 추가
|
||||
$data['files'] = $this->getItemFiles($id, $tenantId);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -511,6 +515,9 @@ public function getItem(
|
||||
$data['prices'] = $this->fetchPrices('PRODUCT', $id, $clientId, $priceDate);
|
||||
}
|
||||
|
||||
// 파일 정보 추가
|
||||
$data['files'] = $this->getItemFiles($id, $tenantId);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -1119,6 +1126,36 @@ private function batchDeleteMaterials(array $ids): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목의 파일 목록 조회 (field_key별 그룹핑)
|
||||
*
|
||||
* @param int $itemId 품목 ID
|
||||
* @param int $tenantId 테넌트 ID
|
||||
* @return array field_key별로 그룹핑된 파일 목록
|
||||
*/
|
||||
private function getItemFiles(int $itemId, int $tenantId): array
|
||||
{
|
||||
$files = File::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('document_type', '1') // ITEM_GROUP_ID
|
||||
->where('document_id', $itemId)
|
||||
->whereNull('deleted_at')
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
if ($files->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $files->groupBy('file_type')->map(function ($group) {
|
||||
return $group->map(fn ($file) => [
|
||||
'id' => $file->id,
|
||||
'file_name' => $file->display_name ?? $file->file_name,
|
||||
'file_path' => $file->file_path,
|
||||
])->values()->toArray();
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 상세 조회 (code 기반, BOM 포함 옵션)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user