AttachmentMapper.java
역할
- AttachmentEntity → AttachmentResponse DTO 변환 전용 클래스
- Service 내부에서 private 메서드 대신 분리하여 재사용 가능
- 다른 Service/Controller에서도 Entity → DTO 변환에 활용
1. 메서드
public static AttachmentResponse toResponse(AttachmentEntity a) {
return new AttachmentResponse(
a.getId(),
a.getOriginalFilename(),
a.getContentType(),
a.getSizeBytes(),
a.getStoragePath()
);
}
- toResponse() → Entity에서 DTO로 변환
- Entity의 필드 값을 그대로 DTO에 매핑
2. 특징
- 재사용 가능 → 여러 Service/Controller에서 호출 가능
- Static 메서드 → 인스턴스 생성 없이 바로 사용 가능
- DTO 변환 전용 → 비즈니스 로직 없음
- 코드 간결화 → Service에서 반복되는 변환 로직 제거
3. 설명 포인트
- AttachmentController/Service에서 응답용 DTO 생성 시 사용
- Entity와 DTO 사이의 분리 원칙 준수