feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services\Equipment;
|
|
|
|
|
|
2026-03-12 13:45:15 +09:00
|
|
|
use App\Models\Commons\File;
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
use App\Models\Equipment\Equipment;
|
|
|
|
|
use App\Services\Service;
|
2026-03-12 13:45:15 +09:00
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
|
|
|
|
|
|
class EquipmentPhotoService extends Service
|
|
|
|
|
{
|
2026-03-12 13:45:15 +09:00
|
|
|
private const MAX_PHOTOS = 10;
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
|
2026-03-12 13:45:15 +09:00
|
|
|
public function index(int $equipmentId): array
|
|
|
|
|
{
|
|
|
|
|
$equipment = $this->getEquipment($equipmentId);
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
|
2026-03-12 13:45:15 +09:00
|
|
|
return $equipment->photos->map(fn ($file) => $this->formatFileResponse($file))->values()->toArray();
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 13:45:15 +09:00
|
|
|
/**
|
|
|
|
|
* @param UploadedFile[] $files
|
|
|
|
|
*/
|
|
|
|
|
public function store(int $equipmentId, array $files): array
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
{
|
2026-03-12 13:45:15 +09:00
|
|
|
$equipment = $this->getEquipment($equipmentId);
|
|
|
|
|
$tenantId = $this->tenantId();
|
|
|
|
|
$userId = $this->apiUserId();
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
|
2026-03-12 13:45:15 +09:00
|
|
|
$currentCount = File::where('document_id', $equipmentId)
|
|
|
|
|
->where('document_type', 'equipment')
|
|
|
|
|
->whereNull('deleted_at')
|
|
|
|
|
->count();
|
|
|
|
|
|
|
|
|
|
if ($currentCount + count($files) > self::MAX_PHOTOS) {
|
|
|
|
|
throw new \Exception(__('error.equipment.photo_limit_exceeded'));
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 13:45:15 +09:00
|
|
|
$uploaded = [];
|
|
|
|
|
|
|
|
|
|
foreach ($files as $uploadedFile) {
|
|
|
|
|
$extension = $uploadedFile->getClientOriginalExtension();
|
|
|
|
|
$storedName = bin2hex(random_bytes(8)).'.'.$extension;
|
|
|
|
|
$displayName = $uploadedFile->getClientOriginalName();
|
|
|
|
|
|
|
|
|
|
$year = date('Y');
|
|
|
|
|
$month = date('m');
|
|
|
|
|
$directory = sprintf('%d/equipment/%s/%s', $tenantId, $year, $month);
|
|
|
|
|
$filePath = $directory.'/'.$storedName;
|
|
|
|
|
|
|
|
|
|
Storage::disk('r2')->putFileAs($directory, $uploadedFile, $storedName);
|
|
|
|
|
|
|
|
|
|
$mimeType = $uploadedFile->getMimeType();
|
|
|
|
|
|
|
|
|
|
$file = File::create([
|
|
|
|
|
'tenant_id' => $tenantId,
|
|
|
|
|
'display_name' => $displayName,
|
|
|
|
|
'stored_name' => $storedName,
|
|
|
|
|
'file_path' => $filePath,
|
|
|
|
|
'file_size' => $uploadedFile->getSize(),
|
|
|
|
|
'mime_type' => $mimeType,
|
|
|
|
|
'file_type' => 'image',
|
|
|
|
|
'document_id' => $equipmentId,
|
|
|
|
|
'document_type' => 'equipment',
|
|
|
|
|
'is_temp' => false,
|
|
|
|
|
'uploaded_by' => $userId,
|
|
|
|
|
'created_by' => $userId,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$uploaded[] = $this->formatFileResponse($file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $uploaded;
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 13:45:15 +09:00
|
|
|
public function destroy(int $equipmentId, int $fileId): array
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
{
|
2026-03-12 13:45:15 +09:00
|
|
|
$tenantId = $this->tenantId();
|
|
|
|
|
$userId = $this->apiUserId();
|
|
|
|
|
|
|
|
|
|
$file = File::where('tenant_id', $tenantId)
|
|
|
|
|
->where('document_id', $equipmentId)
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
->where('document_type', 'equipment')
|
|
|
|
|
->where('id', $fileId)
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
if (! $file) {
|
|
|
|
|
throw new NotFoundHttpException(__('error.file.not_found'));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 13:45:15 +09:00
|
|
|
$file->softDeleteFile($userId);
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'file_id' => $fileId,
|
|
|
|
|
'deleted' => true,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getEquipment(int $equipmentId): Equipment
|
|
|
|
|
{
|
|
|
|
|
$equipment = Equipment::find($equipmentId);
|
|
|
|
|
|
|
|
|
|
if (! $equipment) {
|
|
|
|
|
throw new NotFoundHttpException(__('error.equipment.not_found'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $equipment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function formatFileResponse(File $file): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'id' => $file->id,
|
|
|
|
|
'file_name' => $file->display_name,
|
|
|
|
|
'file_path' => $file->file_path,
|
|
|
|
|
'file_url' => url("/api/v1/files/{$file->id}/download"),
|
|
|
|
|
'file_size' => $file->file_size,
|
|
|
|
|
'mime_type' => $file->mime_type,
|
|
|
|
|
'created_at' => $file->created_at?->format('Y-m-d H:i:s'),
|
|
|
|
|
];
|
feat: [equipment] 설비관리 API 백엔드 구현 (Phase 1)
- 모델 6개: Equipment, EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair, EquipmentProcess
- InspectionCycle Enum: 6주기(일/주/월/격월/분기/반기) 날짜 해석
- 서비스 4개: EquipmentService, EquipmentInspectionService, EquipmentRepairService, EquipmentPhotoService
- 컨트롤러 4개: CRUD + 점검 토글/결과 설정/메모/초기화 + 템플릿 관리 + 수리이력 + 사진
- FormRequest 6개: 설비등록/수정, 수리이력, 점검템플릿, 토글, 메모
- 라우트 26개: equipment prefix 하위 RESTful 엔드포인트
- i18n 메시지: message.equipment.*, error.equipment.*
- 마이그레이션: equipments/equipment_repairs options JSON 컬럼 추가
2026-03-12 10:52:30 +09:00
|
|
|
}
|
|
|
|
|
}
|