- 모델 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 컬럼 추가
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Equipment;
|
|
|
|
use App\Models\Boards\File;
|
|
use App\Models\Equipment\Equipment;
|
|
use App\Services\Service;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class EquipmentPhotoService extends Service
|
|
{
|
|
public function index(int $equipmentId): \Illuminate\Database\Eloquent\Collection
|
|
{
|
|
$equipment = Equipment::find($equipmentId);
|
|
|
|
if (! $equipment) {
|
|
throw new NotFoundHttpException(__('error.equipment.not_found'));
|
|
}
|
|
|
|
return $equipment->photos;
|
|
}
|
|
|
|
public function store(int $equipmentId, array $fileData): File
|
|
{
|
|
$equipment = Equipment::find($equipmentId);
|
|
|
|
if (! $equipment) {
|
|
throw new NotFoundHttpException(__('error.equipment.not_found'));
|
|
}
|
|
|
|
return File::create(array_merge($fileData, [
|
|
'document_id' => $equipmentId,
|
|
'document_type' => 'equipment',
|
|
]));
|
|
}
|
|
|
|
public function destroy(int $equipmentId, int $fileId): bool
|
|
{
|
|
$file = File::where('document_id', $equipmentId)
|
|
->where('document_type', 'equipment')
|
|
->where('id', $fileId)
|
|
->first();
|
|
|
|
if (! $file) {
|
|
throw new NotFoundHttpException(__('error.file.not_found'));
|
|
}
|
|
|
|
return $file->delete();
|
|
}
|
|
}
|