feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
2025-12-11 22:40:55 +09:00
|
|
|
use App\Helpers\ApiResponse;
|
2025-12-12 17:38:22 +09:00
|
|
|
use App\Helpers\ItemTypeHelper;
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
use App\Http\Controllers\Controller;
|
2025-12-12 17:38:22 +09:00
|
|
|
use App\Http\Requests\Item\ItemFileUploadRequest;
|
2025-12-11 22:40:55 +09:00
|
|
|
use App\Models\Commons\File;
|
2025-12-12 17:38:22 +09:00
|
|
|
use App\Models\Materials\Material;
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
use App\Models\Products\Product;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 품목 파일 관리 컨트롤러
|
|
|
|
|
*
|
2025-12-12 17:38:22 +09:00
|
|
|
* group_id 기반 파일 관리, field_key 동적 지원
|
|
|
|
|
* - document_type: group_id (품목 그룹)
|
|
|
|
|
* - document_id: item_id (품목 ID)
|
|
|
|
|
* - file_type: field_key (동적)
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
*/
|
|
|
|
|
class ItemsFileController extends Controller
|
|
|
|
|
{
|
2025-12-12 17:38:22 +09:00
|
|
|
/**
|
|
|
|
|
* 품목 그룹 ID (고정값, 추후 설정으로 변경 가능)
|
|
|
|
|
*/
|
|
|
|
|
private const ITEM_GROUP_ID = '1';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 파일 목록 조회
|
|
|
|
|
*
|
|
|
|
|
* GET /api/v1/items/{id}/files
|
|
|
|
|
*/
|
|
|
|
|
public function index(int $id, Request $request)
|
|
|
|
|
{
|
|
|
|
|
return ApiResponse::handle(function () use ($id, $request) {
|
|
|
|
|
$tenantId = app('tenant_id');
|
|
|
|
|
$itemType = strtoupper($request->input('item_type', 'FG'));
|
|
|
|
|
$fieldKey = $request->input('field_key');
|
|
|
|
|
|
|
|
|
|
// 품목 존재 확인
|
|
|
|
|
$this->getItemById($id, $itemType, $tenantId);
|
|
|
|
|
|
|
|
|
|
// 파일 조회
|
|
|
|
|
$query = File::query()
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->where('document_type', self::ITEM_GROUP_ID)
|
|
|
|
|
->where('document_id', $id);
|
|
|
|
|
|
|
|
|
|
// 특정 field_key만 조회
|
|
|
|
|
if ($fieldKey) {
|
2025-12-12 18:29:14 +09:00
|
|
|
$query->where('field_key', $fieldKey);
|
2025-12-12 17:38:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$files = $query->orderBy('created_at', 'desc')->get();
|
|
|
|
|
|
|
|
|
|
// field_key별 그룹핑
|
2025-12-12 18:29:14 +09:00
|
|
|
$grouped = $files->groupBy('field_key')->map(function ($group) {
|
2025-12-12 17:38:22 +09:00
|
|
|
return $group->map(fn ($file) => $this->formatFileResponse($file))->values();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $grouped;
|
|
|
|
|
}, __('message.fetched'));
|
|
|
|
|
}
|
|
|
|
|
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
/**
|
|
|
|
|
* 파일 업로드
|
|
|
|
|
*
|
2025-11-30 21:05:44 +09:00
|
|
|
* POST /api/v1/items/{id}/files
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
*/
|
2025-12-12 17:38:22 +09:00
|
|
|
public function upload(int $id, ItemFileUploadRequest $request)
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
{
|
2025-11-30 21:05:44 +09:00
|
|
|
return ApiResponse::handle(function () use ($id, $request) {
|
2025-12-11 22:40:55 +09:00
|
|
|
$tenantId = app('tenant_id');
|
|
|
|
|
$userId = auth()->id();
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
$validated = $request->validated();
|
2025-12-12 17:38:22 +09:00
|
|
|
$itemType = strtoupper($validated['item_type'] ?? 'FG');
|
|
|
|
|
$fieldKey = $validated['field_key'];
|
2025-12-11 22:40:55 +09:00
|
|
|
$uploadedFile = $validated['file'];
|
2025-12-12 17:38:22 +09:00
|
|
|
$existingFileId = $validated['file_id'] ?? null;
|
|
|
|
|
|
|
|
|
|
// 품목 존재 확인
|
|
|
|
|
$this->getItemById($id, $itemType, $tenantId);
|
|
|
|
|
|
|
|
|
|
$replaced = false;
|
|
|
|
|
|
|
|
|
|
// 기존 파일 교체 (file_id가 있는 경우)
|
|
|
|
|
if ($existingFileId) {
|
|
|
|
|
$existingFile = File::query()
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->where('document_type', self::ITEM_GROUP_ID)
|
|
|
|
|
->where('document_id', $id)
|
|
|
|
|
->where('id', $existingFileId)
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
if ($existingFile) {
|
|
|
|
|
$existingFile->softDeleteFile($userId);
|
|
|
|
|
$replaced = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-11 22:40:55 +09:00
|
|
|
|
|
|
|
|
// 파일명 생성 (64bit 난수)
|
|
|
|
|
$extension = $uploadedFile->getClientOriginalExtension();
|
2025-12-12 17:38:22 +09:00
|
|
|
$storedName = bin2hex(random_bytes(8)).'.'.$extension;
|
2025-12-11 22:40:55 +09:00
|
|
|
$displayName = $uploadedFile->getClientOriginalName();
|
|
|
|
|
|
|
|
|
|
// 경로 생성: tenants/{tenant_id}/items/{year}/{month}/{stored_name}
|
|
|
|
|
$year = date('Y');
|
|
|
|
|
$month = date('m');
|
|
|
|
|
$directory = sprintf('%d/items/%s/%s', $tenantId, $year, $month);
|
2025-12-12 17:38:22 +09:00
|
|
|
$filePath = $directory.'/'.$storedName;
|
2025-12-11 22:40:55 +09:00
|
|
|
|
|
|
|
|
// 파일 저장 (tenant 디스크)
|
|
|
|
|
Storage::disk('tenant')->putFileAs($directory, $uploadedFile, $storedName);
|
|
|
|
|
|
2025-12-12 18:29:14 +09:00
|
|
|
// file_type 자동 분류 (MIME 타입 기반)
|
|
|
|
|
$mimeType = $uploadedFile->getMimeType();
|
|
|
|
|
$fileType = $this->detectFileType($mimeType);
|
|
|
|
|
|
2025-12-11 22:40:55 +09:00
|
|
|
// files 테이블에 저장
|
|
|
|
|
$file = File::create([
|
|
|
|
|
'tenant_id' => $tenantId,
|
|
|
|
|
'display_name' => $displayName,
|
|
|
|
|
'stored_name' => $storedName,
|
|
|
|
|
'file_path' => $filePath,
|
|
|
|
|
'file_size' => $uploadedFile->getSize(),
|
2025-12-12 18:29:14 +09:00
|
|
|
'mime_type' => $mimeType,
|
|
|
|
|
'file_type' => $fileType, // 파일 형식 (image, document, excel, archive)
|
|
|
|
|
'field_key' => $fieldKey, // 비즈니스 용도 (drawing, certificate 등)
|
2025-12-12 17:38:22 +09:00
|
|
|
'document_id' => $id,
|
|
|
|
|
'document_type' => self::ITEM_GROUP_ID, // group_id
|
2025-12-11 22:40:55 +09:00
|
|
|
'is_temp' => false,
|
|
|
|
|
'uploaded_by' => $userId,
|
|
|
|
|
'created_by' => $userId,
|
|
|
|
|
]);
|
|
|
|
|
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
return [
|
2025-12-11 22:40:55 +09:00
|
|
|
'file_id' => $file->id,
|
2025-12-12 17:38:22 +09:00
|
|
|
'field_key' => $fieldKey,
|
|
|
|
|
'file_url' => $this->getFileUrl($filePath),
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
'file_path' => $filePath,
|
2025-12-11 22:40:55 +09:00
|
|
|
'file_name' => $displayName,
|
|
|
|
|
'file_size' => $file->file_size,
|
|
|
|
|
'mime_type' => $file->mime_type,
|
2025-12-12 17:38:22 +09:00
|
|
|
'replaced' => $replaced,
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
];
|
|
|
|
|
}, __('message.file.uploaded'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 파일 삭제
|
|
|
|
|
*
|
2025-12-12 17:38:22 +09:00
|
|
|
* DELETE /api/v1/items/{id}/files/{fileId}
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
*/
|
2025-12-12 17:38:22 +09:00
|
|
|
public function delete(int $id, int $fileId, Request $request)
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
{
|
2025-12-12 17:38:22 +09:00
|
|
|
return ApiResponse::handle(function () use ($id, $fileId, $request) {
|
|
|
|
|
$tenantId = app('tenant_id');
|
2025-12-11 22:40:55 +09:00
|
|
|
$userId = auth()->id();
|
2025-12-12 17:38:22 +09:00
|
|
|
$itemType = strtoupper($request->input('item_type', 'FG'));
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
|
2025-12-12 17:38:22 +09:00
|
|
|
// 품목 존재 확인
|
|
|
|
|
$this->getItemById($id, $itemType, $tenantId);
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
|
2025-12-12 17:38:22 +09:00
|
|
|
// 파일 조회
|
|
|
|
|
$file = File::query()
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->where('document_type', self::ITEM_GROUP_ID)
|
|
|
|
|
->where('document_id', $id)
|
|
|
|
|
->where('id', $fileId)
|
|
|
|
|
->first();
|
2025-12-11 22:40:55 +09:00
|
|
|
|
2025-12-12 17:38:22 +09:00
|
|
|
if (! $file) {
|
|
|
|
|
throw new NotFoundHttpException(__('error.file.not_found'));
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
}
|
|
|
|
|
|
2025-12-12 17:38:22 +09:00
|
|
|
// Soft delete
|
|
|
|
|
$file->softDeleteFile($userId);
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
|
|
|
|
|
return [
|
2025-12-12 17:38:22 +09:00
|
|
|
'file_id' => $fileId,
|
|
|
|
|
'deleted' => true,
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
];
|
|
|
|
|
}, __('message.file.deleted'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-12 17:38:22 +09:00
|
|
|
* ID로 품목 조회 (Product 또는 Material)
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
*/
|
2025-12-12 17:38:22 +09:00
|
|
|
private function getItemById(int $id, string $itemType, int $tenantId): Product|Material
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
{
|
2025-12-12 17:38:22 +09:00
|
|
|
if (ItemTypeHelper::isMaterial($itemType, $tenantId)) {
|
|
|
|
|
$item = Material::query()
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->find($id);
|
|
|
|
|
} else {
|
|
|
|
|
$item = Product::query()
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->find($id);
|
|
|
|
|
}
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
|
2025-12-12 17:38:22 +09:00
|
|
|
if (! $item) {
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
throw new NotFoundHttpException(__('error.not_found'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-12 17:38:22 +09:00
|
|
|
return $item;
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-12 17:38:22 +09:00
|
|
|
* 파일 응답 포맷
|
2025-12-11 22:40:55 +09:00
|
|
|
*/
|
2025-12-12 17:38:22 +09:00
|
|
|
private function formatFileResponse(File $file): array
|
2025-12-11 22:40:55 +09:00
|
|
|
{
|
2025-12-12 17:38:22 +09:00
|
|
|
return [
|
|
|
|
|
'id' => $file->id,
|
|
|
|
|
'file_name' => $file->display_name,
|
|
|
|
|
'file_path' => $file->file_path,
|
|
|
|
|
'file_url' => $this->getFileUrl($file->file_path),
|
|
|
|
|
'file_size' => $file->file_size,
|
|
|
|
|
'mime_type' => $file->mime_type,
|
2025-12-12 18:29:14 +09:00
|
|
|
'file_type' => $file->file_type,
|
|
|
|
|
'field_key' => $file->field_key,
|
2025-12-12 17:38:22 +09:00
|
|
|
'created_at' => $file->created_at?->format('Y-m-d H:i:s'),
|
|
|
|
|
];
|
2025-12-11 22:40:55 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-12 17:38:22 +09:00
|
|
|
* 파일 URL 생성
|
2025-12-11 22:40:55 +09:00
|
|
|
*/
|
|
|
|
|
private function getFileUrl(string $filePath): string
|
|
|
|
|
{
|
2025-12-12 17:38:22 +09:00
|
|
|
return url('/api/v1/files/download/'.base64_encode($filePath));
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
}
|
2025-12-12 18:29:14 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* MIME 타입 기반 파일 형식 분류
|
|
|
|
|
*/
|
|
|
|
|
private function detectFileType(string $mimeType): string
|
|
|
|
|
{
|
|
|
|
|
if (str_starts_with($mimeType, 'image/')) {
|
|
|
|
|
return 'image';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in_array($mimeType, [
|
|
|
|
|
'application/vnd.ms-excel',
|
|
|
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
|
|
'text/csv',
|
|
|
|
|
])) {
|
|
|
|
|
return 'excel';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in_array($mimeType, [
|
|
|
|
|
'application/zip',
|
|
|
|
|
'application/x-rar-compressed',
|
|
|
|
|
'application/x-7z-compressed',
|
|
|
|
|
'application/gzip',
|
|
|
|
|
])) {
|
|
|
|
|
return 'archive';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 기본값: document (pdf, doc, hwp 등)
|
|
|
|
|
return 'document';
|
|
|
|
|
}
|
2025-12-12 17:38:22 +09:00
|
|
|
}
|