Conversation
(자격증, 해시태그 X)
+ ("/api/trainers/**" 임시 허가)
1749efe to
2754bf6
Compare
| // 날짜/시간 타입(JSON 직렬화 지원) | ||
| implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' |
There was a problem hiding this comment.
spring-boot-starter-web를 추가하면 jsr310이 자동으로 추가되기 때문에 의존성을 추가하지 않아도 괜찮습니다!
| return new TrainerAddress( | ||
| null, | ||
| null, | ||
| dto.getRoadAddress(), | ||
| dto.getDetailAddress(), | ||
| null, | ||
| coordinates | ||
| ); |
There was a problem hiding this comment.
null 주입을 TrainerAddress 생성자 내부에서 처리해도 좋을 것 같아요
| @Override | ||
| public Optional<TrainerAddress> findById(Long addressId) { | ||
| return jpaRepository.findById(addressId) | ||
| .map(entity -> new TrainerAddress( | ||
| entity.getId(), | ||
| entity.getNumberAddress(), | ||
| entity.getRoadAddress(), | ||
| entity.getDetailAddress(), | ||
| entity.getPostalCode(), | ||
| new Coordinates(entity.getLatitude(), entity.getLongitude()) | ||
| )); | ||
| } |
There was a problem hiding this comment.
저는 매핑을 레포지토리보단 서비스에서 하는게 좋을 것 같다고 생각해요
레포지토리 내부에서 매핑을 사용한다면 재사용성이 떨어집니다.
그리고 jpa가 아닌 다른 서비스로 변경할 경우 레포지토리를 새로 추가해야 하는데 매핑 로직까지 새로 작성해야하는 문제도 발생합니다.
마지막으로 레포지토리의 책임이 많다는 생각이 듭니다. 레포지토리는 데이터 조회랑 저장까지만 담당하고 그걸 변형하거나 검증하는 등의 비즈니스 로직은 서비스에서 담당하는게 좋을 것 같아요
There was a problem hiding this comment.
저는 매핑을 레포지토리보단 서비스에서 하는게 좋을 것 같다고 생각해요 레포지토리 내부에서 매핑을 사용한다면 재사용성이 떨어집니다. 그리고 jpa가 아닌 다른 서비스로 변경할 경우 레포지토리를 새로 추가해야 하는데 매핑 로직까지 새로 작성해야하는 문제도 발생합니다. 마지막으로 레포지토리의 책임이 많다는 생각이 듭니다. 레포지토리는 데이터 조회랑 저장까지만 담당하고 그걸 변형하거나 검증하는 등의 비즈니스 로직은 서비스에서 담당하는게 좋을 것 같아요
생각해보니 그렇네요! 수정해보도록 하겠습니다!!
| Long userId = 4L; // TODO: 로그인 사용자 임시 | ||
|
|
||
| trainerProfileService.createProfile(request, userId); | ||
| return ResponseEntity.status(201).body(ApiResponse.created("트레이너 프로필이 성공적으로 등록되었습니다.")); |
There was a problem hiding this comment.
response에 Location 헤더의 추가가 필요할 것 같습니다!
| AccountEntity trainer = em.getReference(AccountEntity.class, profile.getUserId()); | ||
| TrainerAddressEntity address = em.getReference(TrainerAddressEntity.class, profile.getAddressId()); | ||
|
|
||
| AccountEntity trainer = em.getReference(AccountEntity.class, profile.getUserId()); | ||
| TrainerAddressEntity address = em.getReference(TrainerAddressEntity.class, profile.getAddressId()); | ||
| TrainerProfileEntity entity = TrainerProfileMapper.toEntity(profile, trainer, address); |
There was a problem hiding this comment.
저장해야할 엔티티는 서비스에서 생성한 후 레포지토리로 넘기는게 좋을 것 같다고 생각합니다.
AccountEntity랑 TrainerAdderssEntity도 getReference를 사용하기보단 레포지토리를 통해서 직접 조회하여 검증한 다음, TrainerProfileEntity에 넣어주는게 좋을 것 같아요
#️⃣연관된 이슈
📝작업 내용
스크린샷 (선택)
💬리뷰 요구사항(선택)