feat: [items] 아이템 API 기능 개선

- ItemsController, ItemsBomController, ItemsFileController 수정
- ItemBatchDeleteRequest 추가
- ItemsService 개선
- ItemsApi Swagger 문서 업데이트
This commit is contained in:
2025-11-30 21:05:44 +09:00
parent d27e47108d
commit f09fa3791c
6 changed files with 208 additions and 97 deletions

View File

@@ -14,7 +14,7 @@
/**
* 품목 파일 관리 컨트롤러
*
* Code-based 파일 업로드/삭제 API
* ID-based 파일 업로드/삭제 API
* - 절곡도 (bending_diagram)
* - 시방서 (specification)
* - 인정서 (certification)
@@ -24,18 +24,18 @@ class ItemsFileController extends Controller
/**
* 파일 업로드
*
* POST /api/v1/items/{code}/files
* POST /api/v1/items/{id}/files
*/
public function upload(string $code, ItemsFileUploadRequest $request)
public function upload(int $id, ItemsFileUploadRequest $request)
{
return ApiResponse::handle(function () use ($code, $request) {
$product = $this->getProductByCode($code);
return ApiResponse::handle(function () use ($id, $request) {
$product = $this->getProductById($id);
$validated = $request->validated();
$fileType = $request->route('type') ?? $validated['type'];
$file = $validated['file'];
// 파일 저장 경로: items/{code}/{type}/{filename}
$directory = sprintf('items/%s/%s', $code, $fileType);
// 파일 저장 경로: items/{id}/{type}/{filename}
$directory = sprintf('items/%d/%s', $id, $fileType);
$filePath = Storage::disk('public')->putFile($directory, $file);
$fileUrl = Storage::disk('public')->url($filePath);
$originalName = $file->getClientOriginalName();
@@ -57,12 +57,12 @@ public function upload(string $code, ItemsFileUploadRequest $request)
/**
* 파일 삭제
*
* DELETE /api/v1/items/{code}/files/{type}
* DELETE /api/v1/items/{id}/files/{type}
*/
public function delete(string $code, string $type, Request $request)
public function delete(int $id, string $type, Request $request)
{
return ApiResponse::handle(function () use ($code, $type) {
$product = $this->getProductByCode($code);
return ApiResponse::handle(function () use ($id, $type) {
$product = $this->getProductById($id);
// 파일 타입 검증
if (! in_array($type, ['bending_diagram', 'specification', 'certification'])) {
@@ -90,15 +90,14 @@ public function delete(string $code, string $type, Request $request)
}
/**
* 코드로 Product 조회
* ID로 Product 조회
*/
private function getProductByCode(string $code): Product
private function getProductById(int $id): Product
{
$tenantId = app('tenant_id');
$product = Product::query()
->where('tenant_id', $tenantId)
->where('code', $code)
->first();
->find($id);
if (! $product) {
throw new NotFoundHttpException(__('error.not_found'));