-
Notifications
You must be signed in to change notification settings - Fork 0
[CMAT-45] feat: Planner 2개로 수정 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package UMC.career_mate.domain.planner.dto.request; | ||
|
|
||
| import UMC.career_mate.global.response.exception.GeneralException; | ||
| import UMC.career_mate.global.response.exception.code.CommonErrorCode; | ||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Builder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Builder | ||
| public record CreatePlannerListDTO( | ||
|
|
||
| @NotNull(message = "플래너 목록은 필수입니다.") | ||
| @Valid | ||
| List<CreatePlannerDTO> planners | ||
| ) { | ||
| public CreatePlannerListDTO { | ||
|
|
||
| if (planners == null || planners.size() != 2) { | ||
| throw new GeneralException(CommonErrorCode.INVALID_PLANNER_COUNT); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package UMC.career_mate.domain.planner.dto.response; | ||
|
|
||
| import UMC.career_mate.domain.planner.Planner; | ||
| import lombok.Builder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Builder | ||
| public record PlannerListResponseDTO( | ||
| List<PlannerResponseDTO> planners | ||
| ) { | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||||||||||||||||||||||||||||||
| import UMC.career_mate.domain.planner.Planner; | ||||||||||||||||||||||||||||||||||||||
| import UMC.career_mate.domain.planner.converter.PlannerConverter; | ||||||||||||||||||||||||||||||||||||||
| import UMC.career_mate.domain.planner.dto.request.CreatePlannerDTO; | ||||||||||||||||||||||||||||||||||||||
| import UMC.career_mate.domain.planner.dto.request.CreatePlannerListDTO; | ||||||||||||||||||||||||||||||||||||||
| import UMC.career_mate.domain.planner.repository.PlannerRepository; | ||||||||||||||||||||||||||||||||||||||
| import UMC.career_mate.global.response.exception.GeneralException; | ||||||||||||||||||||||||||||||||||||||
| import UMC.career_mate.global.response.exception.code.CommonErrorCode; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -12,6 +13,9 @@ | |||||||||||||||||||||||||||||||||||||
| import org.springframework.stereotype.Service; | ||||||||||||||||||||||||||||||||||||||
| import org.springframework.transaction.annotation.Transactional; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import java.util.Iterator; | ||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @Slf4j | ||||||||||||||||||||||||||||||||||||||
| @Service | ||||||||||||||||||||||||||||||||||||||
| @RequiredArgsConstructor | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -20,25 +24,35 @@ public class PlannerCommandService { | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private final PlannerRepository plannerRepository; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public void savePlanner(Member member, CreatePlannerDTO createPlannerDTO){ | ||||||||||||||||||||||||||||||||||||||
| public void savePlanner(Member member){ | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 메서드 시그니처 명칭과 실제 동작 간의 괴리 - public void savePlanner(Member member){
+ public void initializePlanners(Member member){📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| if(plannerRepository.existsByMember(member)){ | ||||||||||||||||||||||||||||||||||||||
| throw new GeneralException(CommonErrorCode.PLANNER_EXISTS); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| Planner planner = PlannerConverter.toPlanner(member, createPlannerDTO); | ||||||||||||||||||||||||||||||||||||||
| plannerRepository.save(planner); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| List<CreatePlannerDTO> createPlannerDTOList = List.of( | ||||||||||||||||||||||||||||||||||||||
| CreatePlannerDTO.builder().build(), | ||||||||||||||||||||||||||||||||||||||
| CreatePlannerDTO.builder().build() | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| plannerRepository.saveAll(PlannerConverter.toPlannerList(member, createPlannerDTOList)); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public void editPlanner(Member member, CreatePlannerDTO createPlannerDTO){ | ||||||||||||||||||||||||||||||||||||||
| Planner planner = plannerRepository.findPlannerByMember(member).orElseThrow( | ||||||||||||||||||||||||||||||||||||||
| ()->new GeneralException(CommonErrorCode.PLANNER_NOT_EXISTS)); | ||||||||||||||||||||||||||||||||||||||
| public void editPlanner(Member member, CreatePlannerListDTO createPlannerListDTO){ | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| List<Planner> planners = plannerRepository.findByMember(member); | ||||||||||||||||||||||||||||||||||||||
| List<CreatePlannerDTO> plannerDTOs = createPlannerListDTO.planners(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Iterator<CreatePlannerDTO> dtoIterator = plannerDTOs.iterator(); | ||||||||||||||||||||||||||||||||||||||
| planners.forEach(planner -> planner.update(dtoIterator.next())); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 플래너 개수와 DTO 목록 개수 불일치 시 예외 처리 필요 List<CreatePlannerDTO> plannerDTOs = createPlannerListDTO.planners();
if (planners.size() != plannerDTOs.size()) {
+ throw new GeneralException(CommonErrorCode.INVALID_REQUEST, "DTO 개수와 플래너 개수가 일치하지 않습니다.");
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| planner.update(createPlannerDTO); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public void deletePlanner(Member member){ | ||||||||||||||||||||||||||||||||||||||
| Planner planner = plannerRepository.findPlannerByMember(member).orElseThrow( | ||||||||||||||||||||||||||||||||||||||
| ()->new GeneralException(CommonErrorCode.PLANNER_NOT_EXISTS)); | ||||||||||||||||||||||||||||||||||||||
| plannerRepository.delete(planner); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| List<Planner> planners = plannerRepository.findByMember(member); | ||||||||||||||||||||||||||||||||||||||
| plannerRepository.deleteAll(planners); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import UMC.career_mate.domain.member.Member; | ||
| import UMC.career_mate.domain.planner.Planner; | ||
| import UMC.career_mate.domain.planner.converter.PlannerConverter; | ||
| import UMC.career_mate.domain.planner.dto.response.PlannerListResponseDTO; | ||
| import UMC.career_mate.domain.planner.dto.response.PlannerResponseDTO; | ||
| import UMC.career_mate.domain.planner.repository.PlannerRepository; | ||
| import UMC.career_mate.global.response.exception.GeneralException; | ||
|
|
@@ -12,6 +13,8 @@ | |
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
|
|
@@ -20,11 +23,8 @@ public class PlannerQueryService { | |
|
|
||
| private final PlannerRepository plannerRepository; | ||
|
|
||
| public PlannerResponseDTO getPlannerByMember(Member member) { | ||
| Planner planner = plannerRepository.findPlannerByMember(member).orElseThrow( | ||
| ()-> new GeneralException(CommonErrorCode.PLANNER_NOT_EXISTS) | ||
| ); | ||
|
|
||
| return PlannerConverter.toPlannerResponseDTO(planner); | ||
| public PlannerListResponseDTO getPlannerByMember(Member member) { | ||
| List<Planner> planners = plannerRepository.findByMember(member); | ||
| return PlannerConverter.toPlannerListResponseDTO(planners); | ||
|
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 빈 리스트 처리 로직이 필요합니다. 현재 구현에서는 플래너가 없는 경우에 대한 명시적인 처리가 없습니다. 다음과 같이 개선하면 좋을 것 같습니다: public PlannerListResponseDTO getPlannerByMember(Member member) {
List<Planner> planners = plannerRepository.findByMember(member);
+ if (planners.isEmpty()) {
+ throw new GeneralException(CommonErrorCode.PLANNER_NOT_EXISTS);
+ }
return PlannerConverter.toPlannerListResponseDTO(planners);
}
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.