Conversation
| CapsuleResponseDto responseDto = capsuleService.createCapsule(requestDto); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); |
There was a problem hiding this comment.
비즈니스 레이어 메소드가 리턴 값이 있는 경우 ResponseEntity 리턴에 인라인으로 합쳐도 될 듯 합니다
return ResponseEntity.status(HttpStatus.CREATED).body(capsuleService.createCapsule(requestDto));| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class CapsuleDto { |
There was a problem hiding this comment.
Request와 Response처럼 역할이 완전히 다른 DTO를 함께 이너 클래스로 두는 것은 단일 책임 원칙에 위배된다는 생각이 들긴 합니다만
지금처럼 작은 프로젝트에서는 큰 문제 없을 듯 하므로 그대로 유지해도 무방해보입니다
다만 프로젝트 규모가 더 커지고, 한 도메인에서 사용되는 DTO 및 VO 클래스가 많아진다면 그 때는 역할 별로 DTO도 클래스를 분리하는 것을 추천합니다~
| private String originalFileName; | ||
|
|
||
| public static MediaDto toDto(Media media) { | ||
| String cid = media.getCid(); |
There was a problem hiding this comment.
빌더에서 바로 초기화해도 될 것 같은데 따로 초기화 된 이유가 있을까요?
| private User getCurrentUser() { | ||
| Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
| if (authentication == null || !authentication.isAuthenticated()) { | ||
| throw new CustomException(ErrorCode.UNAUTHORIZED); | ||
| } | ||
| String userEmail = authentication.getName(); | ||
|
|
||
| return userRepository.findByEmail(userEmail) | ||
| .orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)); | ||
| } |
There was a problem hiding this comment.
사용자 정보를 불러오는 로직은 Capsule 과는 전혀 연관되지 않는데 별도의 서비스로 분리하는 게 어떨까요? 예를들어 UserService
There was a problem hiding this comment.
캡슐 CRUD에 사용자의 로그인 정보를 불러오는 로직이 필요해서 추가했습니다. 만약 수정이 필요하다면 바로 수정하도록 하겠습니다.
| capsule.setUser(currentUser); | ||
|
|
||
| Capsule savedCapsule = capsuleRepository.save(capsule); | ||
| System.out.println("Capsule 저장 완료, ID: " + savedCapsule.getId()); |
There was a problem hiding this comment.
print문은 개발 때에만 잠깐 사용하고 실제 로깅은 Slf4j를 통해 하는 걸 추천합니다
| Capsule capsule = requestDto.toEntity(); | ||
| capsule.setUser(currentUser); |
There was a problem hiding this comment.
Entity 변환 시 User를 인자로 전달해 객체 인스턴스 생성과 동시에 초기화 하는 것이 좋아보입니다
객체 인스턴스 생성 후 상태 변경은 객체 내부적으로만 수행하는 것이 적절하므로 setter 사용은 지양하는 것이 좋습니다
| private User user; | ||
|
|
||
| @Builder | ||
| public Capsule(String title, CapsuleType type, String content, LocalDate openDate, User user) { |
|
전체적으로 잘 설계하신 것 같습니다!
|
|
긴 시간동안 코드 리뷰 해주셔서 감사드립니다! |
개인적으론 정말 특수한 경우를 제외하곤 setter 사용은 아예 지양하는 것이 좋다고 생각합니다 |
|
네 감사합니다 바로 수정해서 다시 올리도록 하겠습니다 |
|
변경사항은 확인 완료했고 스웨거 관련 어노테이션만 간단하게 추가했습니다. 확인 후 코멘트 남겨주세요 |
|
스웨거 관련 어노테이션 확인 완료했습니다 |
[feat] 캡슐 CRUD 구현
😺 Issue
✅ 작업 리스트
Capsule, Media 엔티티 및 1:N 매핑
CapsuleType enum과 DTO 작성
Repository, Service CRUD 구현
REST API 컨트롤러 작성 (파일 업로드 포함)
커스텀 예외 및 글로벌 예외 처리
단위 테스트 및 API 테스트 수행
⚙️ 작업 내용
캡슐과 미디어 데이터를 계층 구조로 관리하고,
REST API로 CRUD 기능 제공
파일 업로드 및 예외 처리를 포함한 안정적 서비스 구현
테스트로 기능 정상 동작 확인
📷 테스트 / 구현 내용
🔧 수정 내용
Controller에서 ResponseEntity return inline
변경 및 코드 간소화
Service에서 user 조회 분리
Entity에서 Setter 제거 및 생성자 정리
DTO를 요청/응답으로 분리하고 builder 패턴 적용
Repository 주석 제거
테스트 코드 리팩토링, 출력문 제거
SecurityUtil 활용해 유저 조회 로직 분리 및 print문 삭제