fix: ItemsFileController 파일 API 오류 수정
- delete() 메서드 타입을 mixed로 변경 + 내부 캐스팅
- userId null 처리 (auth()->id() ?? app('api_user'))
- deleteFile() private 메서드로 삭제 로직 일원화
- getFileUrl()을 file_id 기반으로 변경 (/api/v1/files/{id}/download)
- LOGICAL_RELATIONSHIPS.md items 통합 반영
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 논리적 데이터베이스 관계 문서
|
||||
|
||||
> **자동 생성**: 2025-12-11 21:54:15
|
||||
> **자동 생성**: 2025-12-15 13:50:25
|
||||
> **소스**: Eloquent 모델 관계 분석
|
||||
|
||||
## 📊 모델별 관계 현황
|
||||
@@ -44,7 +44,6 @@ ### categorys
|
||||
|
||||
- **parent()**: belongsTo → `categories`
|
||||
- **children()**: hasMany → `categories`
|
||||
- **products()**: hasMany → `products`
|
||||
- **categoryFields()**: hasMany → `category_fields`
|
||||
|
||||
### category_fields
|
||||
@@ -163,6 +162,18 @@ ### tab_columns
|
||||
|
||||
- **tab()**: belongsTo → `custom_tabs`
|
||||
|
||||
### items
|
||||
**모델**: `App\Models\Items\Item`
|
||||
|
||||
- **category()**: belongsTo → `categories`
|
||||
- **details()**: hasOne → `item_details`
|
||||
- **files()**: morphMany → `files`
|
||||
|
||||
### item_details
|
||||
**모델**: `App\Models\Items\ItemDetail`
|
||||
|
||||
- **item()**: belongsTo → `items`
|
||||
|
||||
### main_requests
|
||||
**모델**: `App\Models\MainRequest`
|
||||
|
||||
@@ -174,14 +185,6 @@ ### main_request_flows
|
||||
- **mainRequest()**: belongsTo → `main_requests`
|
||||
- **flowable()**: morphTo → `(Polymorphic)`
|
||||
|
||||
### materials
|
||||
**모델**: `App\Models\Materials\Material`
|
||||
|
||||
- **category()**: belongsTo → `categories`
|
||||
- **receipts()**: hasMany → `material_receipts`
|
||||
- **lots()**: hasMany → `lots`
|
||||
- **files()**: morphMany → `files`
|
||||
|
||||
### material_inspections
|
||||
**모델**: `App\Models\Materials\MaterialInspection`
|
||||
|
||||
@@ -196,7 +199,7 @@ ### material_inspection_items
|
||||
### material_receipts
|
||||
**모델**: `App\Models\Materials\MaterialReceipt`
|
||||
|
||||
- **material()**: belongsTo → `materials`
|
||||
- **item()**: belongsTo → `items`
|
||||
- **inspections()**: hasMany → `material_inspections`
|
||||
|
||||
### users
|
||||
@@ -242,6 +245,7 @@ ### client_groups
|
||||
### orders
|
||||
**모델**: `App\Models\Orders\Order`
|
||||
|
||||
- **item()**: belongsTo → `items`
|
||||
- **items()**: hasMany → `order_items`
|
||||
- **histories()**: hasMany → `order_histories`
|
||||
- **versions()**: hasMany → `order_versions`
|
||||
@@ -255,6 +259,7 @@ ### order_items
|
||||
**모델**: `App\Models\Orders\OrderItem`
|
||||
|
||||
- **order()**: belongsTo → `orders`
|
||||
- **item()**: belongsTo → `items`
|
||||
- **components()**: hasMany → `order_item_components`
|
||||
|
||||
### order_item_components
|
||||
@@ -290,53 +295,10 @@ ### role_menu_permissions
|
||||
- **role()**: belongsTo → `roles`
|
||||
- **menu()**: belongsTo → `menus`
|
||||
|
||||
### common_codes
|
||||
**모델**: `App\Models\Products\CommonCode`
|
||||
|
||||
- **parent()**: belongsTo → `common_codes`
|
||||
- **children()**: hasMany → `common_codes`
|
||||
|
||||
### parts
|
||||
**모델**: `App\Models\Products\Part`
|
||||
|
||||
- **category()**: belongsTo → `common_codes`
|
||||
- **partType()**: belongsTo → `common_codes`
|
||||
|
||||
### prices
|
||||
**모델**: `App\Models\Products\Price`
|
||||
|
||||
- **clientGroup()**: belongsTo → `client_groups`
|
||||
- **product()**: belongsTo → `products`
|
||||
- **material()**: belongsTo → `materials`
|
||||
- **revisions()**: hasMany → `price_revisions`
|
||||
|
||||
### price_revisions
|
||||
**모델**: `App\Models\Products\PriceRevision`
|
||||
|
||||
- **price()**: belongsTo → `prices`
|
||||
- **changedByUser()**: belongsTo → `users`
|
||||
|
||||
### products
|
||||
**모델**: `App\Models\Products\Product`
|
||||
|
||||
- **category()**: belongsTo → `categories`
|
||||
- **componentLines()**: hasMany → `product_components`
|
||||
- **parentLines()**: hasMany → `product_components`
|
||||
- **children()**: belongsToMany → `products`
|
||||
- **parents()**: belongsToMany → `products`
|
||||
- **files()**: morphMany → `files`
|
||||
|
||||
### product_components
|
||||
**모델**: `App\Models\Products\ProductComponent`
|
||||
|
||||
- **parentProduct()**: belongsTo → `products`
|
||||
- **product()**: belongsTo → `products`
|
||||
- **material()**: belongsTo → `materials`
|
||||
|
||||
### lots
|
||||
**모델**: `App\Models\Qualitys\Lot`
|
||||
|
||||
- **material()**: belongsTo → `materials`
|
||||
- **item()**: belongsTo → `items`
|
||||
- **sales()**: hasMany → `lot_sales`
|
||||
|
||||
### lot_sales
|
||||
@@ -348,6 +310,7 @@ ### quotes
|
||||
**모델**: `App\Models\Quote\Quote`
|
||||
|
||||
- **client()**: belongsTo → `clients`
|
||||
- **item()**: belongsTo → `items`
|
||||
- **finalizer()**: belongsTo → `users`
|
||||
- **creator()**: belongsTo → `users`
|
||||
- **updater()**: belongsTo → `users`
|
||||
|
||||
@@ -71,7 +71,7 @@ public function upload(int $id, ItemFileUploadRequest $request)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($id, $request) {
|
||||
$tenantId = app('tenant_id');
|
||||
$userId = auth()->id();
|
||||
$userId = auth()->id() ?? app('api_user');
|
||||
$validated = $request->validated();
|
||||
$fieldKey = $validated['field_key'];
|
||||
$uploadedFile = $validated['file'];
|
||||
@@ -92,7 +92,7 @@ public function upload(int $id, ItemFileUploadRequest $request)
|
||||
->first();
|
||||
|
||||
if ($existingFile) {
|
||||
$existingFile->softDeleteFile($userId);
|
||||
$this->deleteFile($existingFile);
|
||||
$replaced = true;
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ public function upload(int $id, ItemFileUploadRequest $request)
|
||||
return [
|
||||
'file_id' => $file->id,
|
||||
'field_key' => $fieldKey,
|
||||
'file_url' => $this->getFileUrl($filePath),
|
||||
'file_url' => $this->getFileUrl($file->id),
|
||||
'file_path' => $filePath,
|
||||
'file_name' => $displayName,
|
||||
'file_size' => $file->file_size,
|
||||
@@ -150,11 +150,12 @@ public function upload(int $id, ItemFileUploadRequest $request)
|
||||
*
|
||||
* DELETE /api/v1/items/{id}/files/{fileId}
|
||||
*/
|
||||
public function delete(int $id, int $fileId, Request $request)
|
||||
public function delete(int $id, mixed $fileId, Request $request)
|
||||
{
|
||||
$fileId = (int) $fileId;
|
||||
|
||||
return ApiResponse::handle(function () use ($id, $fileId) {
|
||||
$tenantId = app('tenant_id');
|
||||
$userId = auth()->id();
|
||||
|
||||
// 품목 존재 확인
|
||||
$this->getItemById($id, $tenantId);
|
||||
@@ -172,7 +173,7 @@ public function delete(int $id, int $fileId, Request $request)
|
||||
}
|
||||
|
||||
// Soft delete
|
||||
$file->softDeleteFile($userId);
|
||||
$this->deleteFile($file);
|
||||
|
||||
return [
|
||||
'file_id' => $fileId,
|
||||
@@ -197,6 +198,15 @@ private function getItemById(int $id, int $tenantId): Item
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일 삭제 (일원화된 삭제 로직)
|
||||
*/
|
||||
private function deleteFile(File $file): void
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? app('api_user'));
|
||||
$file->softDeleteFile($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일 응답 포맷
|
||||
*/
|
||||
@@ -206,7 +216,7 @@ private function formatFileResponse(File $file): array
|
||||
'id' => $file->id,
|
||||
'file_name' => $file->display_name,
|
||||
'file_path' => $file->file_path,
|
||||
'file_url' => $this->getFileUrl($file->file_path),
|
||||
'file_url' => $this->getFileUrl($file->id),
|
||||
'file_size' => $file->file_size,
|
||||
'mime_type' => $file->mime_type,
|
||||
'file_type' => $file->file_type,
|
||||
@@ -218,9 +228,9 @@ private function formatFileResponse(File $file): array
|
||||
/**
|
||||
* 파일 URL 생성
|
||||
*/
|
||||
private function getFileUrl(string $filePath): string
|
||||
private function getFileUrl(int $fileId): string
|
||||
{
|
||||
return url('/api/v1/files/download/'.base64_encode($filePath));
|
||||
return url("/api/v1/files/{$fileId}/download");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user