AttachmentRepository.java
역할
- AttachmentEntity DB 접근 전용 인터페이스
- JPA를 활용한 CRUD, 조회, 물리 삭제, 통계용 메서드 제공
- Soft delete, Cleanup, Task별 조회 등 첨부파일 관리 기능 전담
1. 주요 메서드
1-1. 업무별 활성 첨부파일 조회
List<AttachmentEntity> findByTaskIdAndIsDeletedFalseOrderByIdDesc(Long taskId);
- 설명
- Task별로 soft delete 되지 않은 파일만 반환
- 최근 업로드 순으로 정렬 (OrderByIdDesc)
- Task 상세 조회 시 첨부파일 리스트 제공용
1-2. 첨부파일 단건 조회 (다운로드/삭제)
java.util.Optional<AttachmentEntity> findByIdAndIsDeletedFalse(Long id);
- 설명
- ID 기준, soft delete 되지 않은 경우만 조회
- 권한 체크 후 다운로드/삭제 로직에서 사용
1-3. Cleanup 대상 조회 (soft delete 후 일정 기간 지난 파일)
@Query("""
select a
from AttachmentEntity a
where a.isDeleted = true
and a.deletedAt is not null
and a.deletedAt < :cutoff
order by a.deletedAt asc
""")
List<AttachmentEntity> findCleanupTargets(@Param("cutoff") LocalDateTime cutoff);
- 설명
- AttachmentCleanupJob 등에서 사용
- retentionDays 이전 soft delete 된 파일만 대상
- 오래된 것부터 처리 → deletedAt 오름차순
- 실제 파일 삭제 시 DB row 참조용
1-4. 물리 삭제 (DB row 제거)