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
This commit is contained in:
2025-11-17 13:40:07 +09:00
parent 2f2fffb6f0
commit 4749761519
10 changed files with 609 additions and 3 deletions

View File

@@ -0,0 +1,109 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
/**
* 품목 파일 업로드 요청 검증
*
* 지원 파일 타입:
* - bending_diagram: 절곡도 (이미지)
* - specification: 시방서 (문서)
* - certification: 인정서 (문서)
*/
class ItemsFileUploadRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$fileType = $this->route('type') ?? $this->input('type');
$rules = [
'type' => ['sometimes', 'required', 'string', 'in:bending_diagram,specification,certification'],
];
// 파일 타입별 검증 규칙
if ($fileType === 'bending_diagram') {
$rules['file'] = [
'required',
'file',
'mimes:jpg,jpeg,png,gif,bmp,svg,webp',
'max:10240', // 10MB
];
} else {
// specification, certification - 문서 파일
$rules['file'] = [
'required',
'file',
'mimes:pdf,doc,docx,xls,xlsx,hwp',
'max:20480', // 20MB
];
}
// 인증 정보 (certification 타입일 때만)
if ($fileType === 'certification') {
$rules['certification_number'] = ['sometimes', 'nullable', 'string', 'max:50'];
$rules['certification_start_date'] = ['sometimes', 'nullable', 'date'];
$rules['certification_end_date'] = ['sometimes', 'nullable', 'date', 'after_or_equal:certification_start_date'];
}
// 절곡 상세 정보 (bending_diagram 타입일 때만)
if ($fileType === 'bending_diagram') {
$rules['bending_details'] = ['sometimes', 'nullable', 'array'];
$rules['bending_details.*.angle'] = ['required_with:bending_details', 'numeric'];
$rules['bending_details.*.length'] = ['required_with:bending_details', 'numeric'];
$rules['bending_details.*.type'] = ['required_with:bending_details', 'string'];
}
return $rules;
}
/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'type' => '파일 타입',
'file' => '파일',
'certification_number' => '인증번호',
'certification_start_date' => '인증 시작일',
'certification_end_date' => '인증 종료일',
'bending_details' => '절곡 상세 정보',
'bending_details.*.angle' => '절곡 각도',
'bending_details.*.length' => '절곡 길이',
'bending_details.*.type' => '절곡 타입',
];
}
/**
* Get custom messages for validator errors.
*
* @return array<string, string>
*/
public function messages(): array
{
return [
'type.in' => '파일 타입은 bending_diagram, specification, certification 중 하나여야 합니다.',
'file.required' => '파일을 선택해주세요.',
'file.mimes' => '허용되지 않는 파일 형식입니다.',
'file.max' => '파일 크기가 너무 큽니다.',
'certification_end_date.after_or_equal' => '인증 종료일은 시작일 이후여야 합니다.',
];
}
}