AttachmentService.java
역할
- 첨부파일 관련 비즈니스 로직 처리 서비스
- Controller 요청 → DB/파일 시스템 연동 → DTO 반환
- Task별 조회, 업로드, 삭제, 다운로드, 통계 등 모든 첨부파일 기능 전담
1. 상수 및 필드
private final AttachmentRepository attachmentRepository; // DB 접근
private final FileStorageService fileStorageService; // 파일 시스템 접근
// 첨부파일 제한
private static final int MAX_FILES = 10; // 한 번에 업로드 가능한 최대 파일 수
private static final long MAX_TOTAL_SIZE = 50L * 1024 * 1024; // 총합 50MB
- attachmentRepository → DB 조회, 저장, 삭제
- fileStorageService → 실제 파일 저장/삭제
- MAX_FILES / MAX_TOTAL_SIZE → 업로드 제한
2. Task별 첨부파일 조회
@Transactional(readOnly = true)
public List<AttachmentResponse> listByTask(Long taskId) {
return attachmentRepository.findByTaskIdAndIsDeletedFalseOrderByIdDesc(taskId)
.stream()
.map(AttachmentMapper::toResponse) // Mapper 사용
.toList();
}
- soft delete 안 된 파일만 조회
- 최근 업로드 순서대로 반환
- Mapper 사용 → Entity → DTO 변환
3. 첨부파일 업로드
@Transactional
public List<AttachmentResponse> uploadToTask(Long taskId, Long uploaderId, List<MultipartFile> files) { ... }