From cd5a5fad12894fdd1a5ebc260000971378526d6e Mon Sep 17 00:00:00 2001 From: oosedus Date: Fri, 6 Sep 2024 23:21:32 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[refactor]=20=EC=A4=91=EA=B0=84=20=ED=9A=8C?= =?UTF-8?q?=EA=B3=A0=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/MidReviewDetailResponse.java | 12 ++++ .../mid_review/domain/model/MidReview.java | 10 ++++ .../mid_review/service/MidReviewService.java | 59 ++++++++++--------- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/example/letscareer/mid_review/domain/dto/response/MidReviewDetailResponse.java b/src/main/java/com/example/letscareer/mid_review/domain/dto/response/MidReviewDetailResponse.java index 824ddbf..25ae686 100644 --- a/src/main/java/com/example/letscareer/mid_review/domain/dto/response/MidReviewDetailResponse.java +++ b/src/main/java/com/example/letscareer/mid_review/domain/dto/response/MidReviewDetailResponse.java @@ -1,5 +1,8 @@ package com.example.letscareer.mid_review.domain.dto.response; +import com.example.letscareer.mid_review.domain.model.MidReview; +import com.example.letscareer.schedule.domain.model.Schedule; +import com.example.letscareer.stage.domain.model.Stage; import jakarta.persistence.Lob; import java.time.LocalDate; @@ -15,4 +18,13 @@ public record MidReviewDetailResponse( @Lob String goal ) { + public static MidReviewDetailResponse from(Schedule schedule, Stage stage, MidReview midReview) { + return new MidReviewDetailResponse( + schedule.getCompany(), + schedule.getDepartment(), + stage.getType().getValue(), + stage.getDate(), + midReview.getFreeReview(), + midReview.getGoal()); + } } diff --git a/src/main/java/com/example/letscareer/mid_review/domain/model/MidReview.java b/src/main/java/com/example/letscareer/mid_review/domain/model/MidReview.java index 8e41523..e60af51 100644 --- a/src/main/java/com/example/letscareer/mid_review/domain/model/MidReview.java +++ b/src/main/java/com/example/letscareer/mid_review/domain/model/MidReview.java @@ -1,5 +1,6 @@ package com.example.letscareer.mid_review.domain.model; +import com.example.letscareer.mid_review.domain.dto.request.PostMidReviewRequest; import com.example.letscareer.stage.domain.model.Stage; import com.example.letscareer.user.domain.User; import jakarta.persistence.*; @@ -29,4 +30,13 @@ public class MidReview { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId", nullable = false) private User user; + + public static MidReview of(PostMidReviewRequest request, Stage stage, User user) { + return MidReview.builder() + .freeReview(request.free_review()) + .goal(request.goal()) + .stage(stage) + .user(user) + .build(); + } } diff --git a/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java b/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java index b4fcc14..06f8d3a 100644 --- a/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java +++ b/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java @@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Optional; + import static com.example.letscareer.common.exception.enums.ErrorCode.*; @Service @@ -28,41 +30,42 @@ public class MidReviewService { private final StageRepository stageRepository; private final UserRepository userRepository; + @Transactional public MidReviewDetailResponse getMidReview(Long userId, Long scheduleId,Long stageId, Long midReviewId){ - User user = userRepository.findByUserId(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - MidReview midReview = midReviewRepository.findByMidReviewIdAndUser(midReviewId, user) - .orElseThrow(()-> new NotFoundException(MID_REVIEW_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findByStageIdAndSchedule(stageId, schedule) - .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); - return new MidReviewDetailResponse( - schedule.getCompany(), - schedule.getDepartment(), - stage.getType().getValue(), - stage.getDate(), - midReview.getFreeReview(), - midReview.getGoal() - ); + User user = getUser(userId); + MidReview midReview = getMidReview(midReviewId, user); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = getStage(stageId, schedule); + return MidReviewDetailResponse.from(schedule, stage, midReview); } @Transactional public void postMidReview(Long userId, Long scheduleId, Long stageId, PostMidReviewRequest request) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findByStageIdAndSchedule(stageId, schedule) + User user = getUser(userId); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = getStage(stageId, schedule); + + MidReview midReview = MidReview.of(request, stage, user); + midReviewRepository.save(midReview); + } + + private Stage getStage(Long stageId, Schedule schedule) { + return stageRepository.findByStageIdAndSchedule(stageId, schedule) .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); + } - MidReview midReview = MidReview.builder() - .freeReview(request.free_review()) - .goal(request.goal()) - .stage(stage) - .user(user) - .build(); + private Schedule getSchedule(Long scheduleId, User user) { + return scheduleRepository.findByUserAndScheduleId(user, scheduleId) + .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); + } - midReviewRepository.save(midReview); + private User getUser(Long userId) { + return userRepository.findByUserId(userId) + .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + } + + private MidReview getMidReview(Long midReviewId, User user) { + return midReviewRepository.findByMidReviewIdAndUser(midReviewId, user) + .orElseThrow(() -> new NotFoundException(MID_REVIEW_NOT_FOUND_EXCEPTION)); } } From 14132651743af352f6df4a5fc5e29461f3f15456 Mon Sep 17 00:00:00 2001 From: oosedus Date: Fri, 6 Sep 2024 23:25:22 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[refactor]=20=EB=A9=B4=EC=A0=91=20=ED=9A=8C?= =?UTF-8?q?=EA=B3=A0=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/IntReviewDetailResponse.java | 13 ++++ .../int_review/domain/model/IntReview.java | 12 +++- .../int_review/service/IntReviewService.java | 60 +++++++++---------- 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/example/letscareer/int_review/domain/dto/response/IntReviewDetailResponse.java b/src/main/java/com/example/letscareer/int_review/domain/dto/response/IntReviewDetailResponse.java index 53fdf11..6d04aaa 100644 --- a/src/main/java/com/example/letscareer/int_review/domain/dto/response/IntReviewDetailResponse.java +++ b/src/main/java/com/example/letscareer/int_review/domain/dto/response/IntReviewDetailResponse.java @@ -1,5 +1,8 @@ package com.example.letscareer.int_review.domain.dto.response; +import com.example.letscareer.int_review.domain.model.IntReview; +import com.example.letscareer.schedule.domain.model.Schedule; +import com.example.letscareer.stage.domain.model.Stage; import jakarta.persistence.Lob; import java.time.LocalDate; @@ -16,4 +19,14 @@ public record IntReviewDetailResponse( @Lob String feelings ) { + public static IntReviewDetailResponse from(Schedule schedule, Stage stage, IntReview intReview) { + return new IntReviewDetailResponse( + schedule.getCompany(), + schedule.getDepartment(), + stage.getType().getValue(), + stage.getDate(), + intReview.getMethod(), + intReview.getQuestions(), + intReview.getFeelings()); + } } diff --git a/src/main/java/com/example/letscareer/int_review/domain/model/IntReview.java b/src/main/java/com/example/letscareer/int_review/domain/model/IntReview.java index ff473cb..b9cf71b 100644 --- a/src/main/java/com/example/letscareer/int_review/domain/model/IntReview.java +++ b/src/main/java/com/example/letscareer/int_review/domain/model/IntReview.java @@ -1,5 +1,6 @@ package com.example.letscareer.int_review.domain.model; +import com.example.letscareer.int_review.domain.dto.request.PostIntReviewRequest; import com.example.letscareer.stage.domain.model.Stage; import com.example.letscareer.user.domain.User; import jakarta.persistence.*; @@ -8,7 +9,6 @@ @Entity @Getter -@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -33,4 +33,14 @@ public class IntReview { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId", nullable = false) private User user; + + public static IntReview of(PostIntReviewRequest request, Stage stage, User user) { + return IntReview.builder() + .method(request.details()) + .questions(request.qa()) + .feelings(request.feel()) + .stage(stage) + .user(user) + .build(); + } } diff --git a/src/main/java/com/example/letscareer/int_review/service/IntReviewService.java b/src/main/java/com/example/letscareer/int_review/service/IntReviewService.java index 3ef6204..e13d1af 100644 --- a/src/main/java/com/example/letscareer/int_review/service/IntReviewService.java +++ b/src/main/java/com/example/letscareer/int_review/service/IntReviewService.java @@ -15,7 +15,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - import static com.example.letscareer.common.exception.enums.ErrorCode.*; @Service @@ -28,44 +27,41 @@ public class IntReviewService { private final StageRepository stageRepository; private final UserRepository userRepository; + @Transactional public IntReviewDetailResponse getIntReview(Long userId, Long scheduleId, Long stageId, Long intReviewId){ - User user = userRepository.findByUserId(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - IntReview intReview = intReviewRepository.findByIntReviewIdAndUser(intReviewId, user) - .orElseThrow(()-> new NotFoundException(INT_REVIEW_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findByStageIdAndSchedule(stageId, schedule) - .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); - return new IntReviewDetailResponse( - schedule.getCompany(), - schedule.getDepartment(), - stage.getType().getValue(), - stage.getDate(), - intReview.getMethod(), - intReview.getQuestions(), - intReview.getFeelings() - - ); + User user = getUser(userId); + IntReview intReview = getIntReview(intReviewId, user); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = getStage(stageId, schedule); + return IntReviewDetailResponse.from(schedule, stage, intReview); } @Transactional public void postIntReview(Long userId, Long scheduleId, Long stageId, PostIntReviewRequest request) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findByStageIdAndSchedule(stageId, schedule) + User user = getUser(userId); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = getStage(stageId, schedule); + IntReview intReview = IntReview.of(request, stage, user); + intReviewRepository.save(intReview); + } + + private Stage getStage(Long stageId, Schedule schedule) { + return stageRepository.findByStageIdAndSchedule(stageId, schedule) .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); + } - IntReview intReview = IntReview.builder() - .stage(stage) - .method(request.details()) - .questions(request.qa()) - .feelings(request.feel()) - .user(user) - .build(); + private Schedule getSchedule(Long scheduleId, User user) { + return scheduleRepository.findByUserAndScheduleId(user, scheduleId) + .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); + } - intReviewRepository.save(intReview); + private IntReview getIntReview(Long intReviewId, User user) { + return intReviewRepository.findByIntReviewIdAndUser(intReviewId, user) + .orElseThrow(() -> new NotFoundException(INT_REVIEW_NOT_FOUND_EXCEPTION)); + } + + private User getUser(Long userId) { + return userRepository.findByUserId(userId) + .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); } } From 59bed158e58ac6caf52472433eb200018c9bdb2c Mon Sep 17 00:00:00 2001 From: oosedus Date: Fri, 6 Sep 2024 23:28:16 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[refactor]=20=EC=9E=90=EA=B8=B0=EC=86=8C?= =?UTF-8?q?=EA=B0=9C=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../letscareer/self_intro/domain/model/SelfIntro.java | 10 ++++++++++ .../self_intro/service/SelfIntroService.java | 7 +------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/letscareer/self_intro/domain/model/SelfIntro.java b/src/main/java/com/example/letscareer/self_intro/domain/model/SelfIntro.java index a255220..d495998 100644 --- a/src/main/java/com/example/letscareer/self_intro/domain/model/SelfIntro.java +++ b/src/main/java/com/example/letscareer/self_intro/domain/model/SelfIntro.java @@ -1,5 +1,6 @@ package com.example.letscareer.self_intro.domain.model; +import com.example.letscareer.self_intro.domain.dto.SelfIntroDTO; import com.example.letscareer.stage.domain.model.Stage; import jakarta.persistence.*; import lombok.*; @@ -27,4 +28,13 @@ public class SelfIntro { @JoinColumn(name = "stageId") @NotNull private Stage stage; + + public static SelfIntro of(SelfIntroDTO selfIntroDTO, Stage stage) { + return SelfIntro.builder() + .title(selfIntroDTO.title()) + .sequence(selfIntroDTO.sequence()) + .content(selfIntroDTO.content()) + .stage(stage) + .build(); + } } diff --git a/src/main/java/com/example/letscareer/self_intro/service/SelfIntroService.java b/src/main/java/com/example/letscareer/self_intro/service/SelfIntroService.java index 2289168..7f713b4 100644 --- a/src/main/java/com/example/letscareer/self_intro/service/SelfIntroService.java +++ b/src/main/java/com/example/letscareer/self_intro/service/SelfIntroService.java @@ -41,12 +41,7 @@ public void saveSelfIntro(Long userId, Long scheduleId, Long stageId, SaveSelfIn // 새로 들어온 자기소개서 항목을 저장한다. for (SelfIntroDTO selfIntroDTO : request.selfIntros()) { - SelfIntro selfIntro = SelfIntro.builder() - .title(selfIntroDTO.title()) - .sequence(selfIntroDTO.sequence()) - .content(selfIntroDTO.content()) - .stage(stage) - .build(); + SelfIntro selfIntro = SelfIntro.of(selfIntroDTO, stage); selfIntroRepository.save(selfIntro); } } From bd03520d91fa4a1767147237d395928f00fc85c8 Mon Sep 17 00:00:00 2001 From: oosedus Date: Fri, 6 Sep 2024 23:57:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[refactor]=20stage=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../self_intro/domain/dto/SelfIntroDTO.java | 10 + .../stage/domain/dto/AppealCareerDTO.java | 9 + .../stage/domain/dto/IntReviewDTO.java | 10 + .../stage/domain/dto/MidReviewDTO.java | 9 + .../letscareer/stage/domain/dto/StageDTO.java | 14 ++ .../domain/dto/converter/StageConverter.java | 39 ++++ .../domain/dto/response/AddStageResponse.java | 13 ++ .../response/GetDocumentStageResponse.java | 9 + .../dto/response/GetStagesResponse.java | 13 ++ .../letscareer/stage/domain/model/Stage.java | 12 + .../stage/service/StageService.java | 214 ++++++------------ 11 files changed, 207 insertions(+), 145 deletions(-) create mode 100644 src/main/java/com/example/letscareer/stage/domain/dto/converter/StageConverter.java diff --git a/src/main/java/com/example/letscareer/self_intro/domain/dto/SelfIntroDTO.java b/src/main/java/com/example/letscareer/self_intro/domain/dto/SelfIntroDTO.java index 13f538b..0e839ec 100644 --- a/src/main/java/com/example/letscareer/self_intro/domain/dto/SelfIntroDTO.java +++ b/src/main/java/com/example/letscareer/self_intro/domain/dto/SelfIntroDTO.java @@ -1,7 +1,17 @@ package com.example.letscareer.self_intro.domain.dto; +import com.example.letscareer.self_intro.domain.model.SelfIntro; + public record SelfIntroDTO( String title, int sequence, String content) { + + public static SelfIntroDTO from(SelfIntro selfIntro) { + return new SelfIntroDTO( + selfIntro.getTitle(), + selfIntro.getSequence(), + selfIntro.getContent() + ); + } } diff --git a/src/main/java/com/example/letscareer/stage/domain/dto/AppealCareerDTO.java b/src/main/java/com/example/letscareer/stage/domain/dto/AppealCareerDTO.java index 16286b5..a340734 100644 --- a/src/main/java/com/example/letscareer/stage/domain/dto/AppealCareerDTO.java +++ b/src/main/java/com/example/letscareer/stage/domain/dto/AppealCareerDTO.java @@ -1,8 +1,17 @@ package com.example.letscareer.stage.domain.dto; +import com.example.letscareer.appealCareer.domain.model.AppealCareer; + public record AppealCareerDTO( Long careerId, String category, String title ) { + public static AppealCareerDTO from(AppealCareer appealCareer) { + return new AppealCareerDTO( + appealCareer.getCareer().getCareerId(), + appealCareer.getCareer().getCategory().getValue(), + appealCareer.getCareer().getTitle() + ); + } } diff --git a/src/main/java/com/example/letscareer/stage/domain/dto/IntReviewDTO.java b/src/main/java/com/example/letscareer/stage/domain/dto/IntReviewDTO.java index a4f9d4e..ece89db 100644 --- a/src/main/java/com/example/letscareer/stage/domain/dto/IntReviewDTO.java +++ b/src/main/java/com/example/letscareer/stage/domain/dto/IntReviewDTO.java @@ -1,9 +1,19 @@ package com.example.letscareer.stage.domain.dto; +import com.example.letscareer.int_review.domain.model.IntReview; + public record IntReviewDTO( Long reviewId, String details, String qa, String feel ) { + public static IntReviewDTO from(IntReview intReview) { + return new IntReviewDTO( + intReview.getIntReviewId(), + intReview.getMethod(), + intReview.getQuestions(), + intReview.getFeelings() + ); + } } diff --git a/src/main/java/com/example/letscareer/stage/domain/dto/MidReviewDTO.java b/src/main/java/com/example/letscareer/stage/domain/dto/MidReviewDTO.java index b769d35..19bedbf 100644 --- a/src/main/java/com/example/letscareer/stage/domain/dto/MidReviewDTO.java +++ b/src/main/java/com/example/letscareer/stage/domain/dto/MidReviewDTO.java @@ -1,8 +1,17 @@ package com.example.letscareer.stage.domain.dto; +import com.example.letscareer.mid_review.domain.model.MidReview; + public record MidReviewDTO( Long reviewId, String free_review, String goal ) { + public static MidReviewDTO from(MidReview midReview) { + return new MidReviewDTO( + midReview.getMidReviewId(), + midReview.getFreeReview(), + midReview.getGoal() + ); + } } diff --git a/src/main/java/com/example/letscareer/stage/domain/dto/StageDTO.java b/src/main/java/com/example/letscareer/stage/domain/dto/StageDTO.java index f983b2c..bb71a88 100644 --- a/src/main/java/com/example/letscareer/stage/domain/dto/StageDTO.java +++ b/src/main/java/com/example/letscareer/stage/domain/dto/StageDTO.java @@ -1,6 +1,9 @@ package com.example.letscareer.stage.domain.dto; +import com.example.letscareer.stage.domain.model.Stage; +import com.example.letscareer.stage.domain.model.Type; + public record StageDTO( Long stageId, int order, @@ -10,4 +13,15 @@ public record StageDTO( String date, String dday ) { + public static StageDTO from(Stage stage, boolean isAlways, String dday) { + return new StageDTO( + stage.getStageId(), + stage.getOrder(), + stage.getType().getValue(), + stage.getType().equals(Type.MID) ? stage.getMidName() : "", + stage.getStatus().getValue(), + isAlways ? "" : stage.getDate().toString(), + dday + ); + } } diff --git a/src/main/java/com/example/letscareer/stage/domain/dto/converter/StageConverter.java b/src/main/java/com/example/letscareer/stage/domain/dto/converter/StageConverter.java new file mode 100644 index 0000000..198c4a2 --- /dev/null +++ b/src/main/java/com/example/letscareer/stage/domain/dto/converter/StageConverter.java @@ -0,0 +1,39 @@ +package com.example.letscareer.stage.domain.dto.converter; + +import com.example.letscareer.appealCareer.domain.model.AppealCareer; +import com.example.letscareer.self_intro.domain.dto.SelfIntroDTO; +import com.example.letscareer.self_intro.domain.model.SelfIntro; +import com.example.letscareer.stage.domain.dto.AppealCareerDTO; +import com.example.letscareer.stage.domain.model.Stage; +import com.example.letscareer.schedule.domain.model.Schedule; +import com.example.letscareer.stage.domain.dto.StageDTO; + +import java.time.LocalDate; +import java.time.Period; +import java.util.List; +import java.util.stream.Collectors; + +public class StageConverter { + public static List toSelfIntroDTOs(List selfIntros) { + return selfIntros.stream() + .map(SelfIntroDTO::from) + .collect(Collectors.toList()); + } + + public static List toAppealCareerDTOs(List appealCareers) { + return appealCareers.stream() + .map(AppealCareerDTO::from) + .collect(Collectors.toList()); + } + + public static List toStageDTOs(List stages, Schedule schedule) { + return stages.stream().map(stage -> { + String dday = !schedule.isAlways() ? String.valueOf(calculateDday(stage.getDate())) : ""; + return StageDTO.from(stage, schedule.isAlways(), dday); + }).collect(Collectors.toList()); + } + + private static int calculateDday(LocalDate date) { + return Period.between(LocalDate.now(), date).getDays(); + } +} diff --git a/src/main/java/com/example/letscareer/stage/domain/dto/response/AddStageResponse.java b/src/main/java/com/example/letscareer/stage/domain/dto/response/AddStageResponse.java index 5ce232d..1acbfe4 100644 --- a/src/main/java/com/example/letscareer/stage/domain/dto/response/AddStageResponse.java +++ b/src/main/java/com/example/letscareer/stage/domain/dto/response/AddStageResponse.java @@ -1,5 +1,8 @@ package com.example.letscareer.stage.domain.dto.response; +import com.example.letscareer.stage.domain.model.Stage; +import com.example.letscareer.stage.domain.model.Type; + import java.time.LocalDate; public record AddStageResponse( @@ -10,4 +13,14 @@ public record AddStageResponse( LocalDate date, int dday ) { + public static AddStageResponse from(Stage stage, Integer dday) { + return new AddStageResponse( + stage.getStageId(), + stage.getType().getValue(), + stage.getType().equals(Type.MID) ? stage.getMidName() : "", + stage.getStatus().getValue(), + stage.getDate(), + dday + ); + } } diff --git a/src/main/java/com/example/letscareer/stage/domain/dto/response/GetDocumentStageResponse.java b/src/main/java/com/example/letscareer/stage/domain/dto/response/GetDocumentStageResponse.java index c318bdd..69419f1 100644 --- a/src/main/java/com/example/letscareer/stage/domain/dto/response/GetDocumentStageResponse.java +++ b/src/main/java/com/example/letscareer/stage/domain/dto/response/GetDocumentStageResponse.java @@ -2,6 +2,7 @@ import com.example.letscareer.self_intro.domain.dto.SelfIntroDTO; import com.example.letscareer.stage.domain.dto.AppealCareerDTO; +import com.example.letscareer.stage.domain.model.Stage; import java.util.List; @@ -11,4 +12,12 @@ public record GetDocumentStageResponse( List selfIntroductions, List appealCareers ) { + public static GetDocumentStageResponse from(Stage stage, List selfIntroductions, List appealCareers) { + return new GetDocumentStageResponse( + stage.getStageId(), + stage.getType().getValue(), + selfIntroductions, + appealCareers + ); + } } diff --git a/src/main/java/com/example/letscareer/stage/domain/dto/response/GetStagesResponse.java b/src/main/java/com/example/letscareer/stage/domain/dto/response/GetStagesResponse.java index fd4b1c9..1f4c089 100644 --- a/src/main/java/com/example/letscareer/stage/domain/dto/response/GetStagesResponse.java +++ b/src/main/java/com/example/letscareer/stage/domain/dto/response/GetStagesResponse.java @@ -1,5 +1,6 @@ package com.example.letscareer.stage.domain.dto.response; +import com.example.letscareer.schedule.domain.model.Schedule; import com.example.letscareer.stage.domain.dto.StageDTO; import java.util.List; @@ -13,4 +14,16 @@ public record GetStagesResponse( boolean isAlways, List stages ) { + + public static GetStagesResponse from(Schedule schedule, List stages) { + return new GetStagesResponse( + schedule.getScheduleId(), + schedule.getCompany(), + schedule.getDepartment(), + schedule.getUrl(), + schedule.getProgress().getValue(), + schedule.isAlways(), + stages + ); + } } diff --git a/src/main/java/com/example/letscareer/stage/domain/model/Stage.java b/src/main/java/com/example/letscareer/stage/domain/model/Stage.java index aa67f58..c608c37 100644 --- a/src/main/java/com/example/letscareer/stage/domain/model/Stage.java +++ b/src/main/java/com/example/letscareer/stage/domain/model/Stage.java @@ -2,6 +2,7 @@ import com.example.letscareer.schedule.domain.dto.request.SchedulePostRequest; import com.example.letscareer.schedule.domain.model.Schedule; +import com.example.letscareer.stage.domain.dto.request.AddStageRequest; import jakarta.persistence.*; import lombok.*; @@ -50,4 +51,15 @@ public static Stage toEntity(Schedule schedule, SchedulePostRequest request) { .status(Status.DO) .build(); } + + public static Stage of(Schedule schedule, AddStageRequest request) { + return Stage.builder() + .schedule(schedule) + .type(request.type()) + .date(request.date()) + .midName(request.mid_name()) + .status(Status.DO) + .order(schedule.getStages().size() + 1) + .build(); + } } diff --git a/src/main/java/com/example/letscareer/stage/service/StageService.java b/src/main/java/com/example/letscareer/stage/service/StageService.java index 75c0302..deba7ae 100644 --- a/src/main/java/com/example/letscareer/stage/service/StageService.java +++ b/src/main/java/com/example/letscareer/stage/service/StageService.java @@ -1,5 +1,6 @@ package com.example.letscareer.stage.service; +import com.example.letscareer.appealCareer.domain.model.AppealCareer; import com.example.letscareer.appealCareer.domain.repository.AppealCareerRepository; import com.example.letscareer.common.exception.model.NotFoundException; import com.example.letscareer.int_review.domain.model.IntReview; @@ -11,6 +12,7 @@ import com.example.letscareer.self_intro.domain.model.SelfIntro; import com.example.letscareer.self_intro.domain.dto.SelfIntroDTO; import com.example.letscareer.self_intro.domain.repository.SelfIntroRepository; +import com.example.letscareer.stage.domain.dto.converter.StageConverter; import com.example.letscareer.stage.domain.model.Stage; import com.example.letscareer.stage.domain.model.Status; import com.example.letscareer.stage.domain.model.Type; @@ -52,180 +54,102 @@ public class StageService { @Transactional public AddStageResponse addStage(Long userId, Long scheduleId, AddStageRequest request) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - - Stage stage = Stage.builder() - .schedule(schedule) - .type(request.type()) - .midName(request.mid_name()) - .date(request.date()) - .status(Status.DO) - .order(schedule.getStages().size() + 1) - .build(); + User user = getUser(userId); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = Stage.of(schedule, request); stageRepository.save(stage); - // D-day 계산 Integer dday = (request.date() != null) ? calculateDday(request.date()) : null; - - return new AddStageResponse( - stage.getStageId(), - stage.getType().getValue(), - stage.getType().equals(Type.MID) ? stage.getMidName() : "", - stage.getStatus().getValue(), - stage.getDate(), - dday); + return AddStageResponse.from(stage, dday); } @Transactional public void updateStageStatus(Long userId, Long scheduleId, Long stageId, UpdateStageStatusRequest request) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findByStageIdAndSchedule(stageId, schedule) - .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); - + User user = getUser(userId); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = getStage(stageId, schedule); stage.setStatus(request.status()); stageRepository.save(stage); } - private int calculateDday(LocalDate deadline) { - int dday = Period.between(LocalDate.now(), deadline).getDays(); - return dday; - } - + @Transactional public GetStagesResponse getStages(Long userId, Long scheduleId) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); + User user = getUser(userId); + Schedule schedule = getSchedule(scheduleId, user); // 해당 스케쥴에 속한 모든 스테이지 조회 List stages = stageRepository.findBySchedule(schedule); - List stageDTOs = new ArrayList<>(); - - for(Stage stage : stages) { - // D-day 계산 - String dday = (!schedule.isAlways()) ? String.valueOf(calculateDday(stage.getDate())) : ""; - stageDTOs.add( - new StageDTO( - stage.getStageId(), - stage.getOrder(), - stage.getType().getValue(), - stage.getType().equals(Type.MID) ? stage.getMidName() : "", - stage.getStatus().getValue(), - schedule.isAlways() ? "" : stage.getDate().toString(), - dday - ) - ); - } - - return new GetStagesResponse( - schedule.getScheduleId(), - schedule.getCompany(), - schedule.getDepartment(), - schedule.getUrl(), - schedule.getProgress().getValue(), - schedule.isAlways(), - stageDTOs); + List stageDTOs = StageConverter.toStageDTOs(stages, schedule);; + + return GetStagesResponse.from(schedule, stageDTOs); } + @Transactional public GetDocumentStageResponse getDocumentStage(Long userId, Long scheduleId, Long stageId) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findByScheduleAndStageIdAndType(schedule, stageId, Type.DOC) - .orElseThrow(() -> new NotFoundException(DOC_STAGE_NOT_FOUND_EXCEPTION)); + User user = getUser(userId); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = getStage(stageId, schedule); + // SelfIntroDTO 변환 List selfIntros = selfIntroRepository.findByStage(stage); - List selfIntroDTOs = new ArrayList<>(); - for(SelfIntro selfIntro : selfIntros) { - selfIntroDTOs.add( - new SelfIntroDTO( - selfIntro.getTitle(), - selfIntro.getSequence(), - selfIntro.getContent() - ) - ); - } - - List appealCareerDTOs = appealCareerRepository.findByStage(stage).stream() - .map(appealCareer -> new AppealCareerDTO( - appealCareer.getCareer().getCareerId(), - appealCareer.getCareer().getCategory().getValue(), - appealCareer.getCareer().getTitle() - )) - .toList(); - - return new GetDocumentStageResponse( - stage.getStageId(), - stage.getType().getValue(), - selfIntroDTOs, - appealCareerDTOs - ); + List selfIntroDTOs = StageConverter.toSelfIntroDTOs(selfIntros); + + // AppealCareerDTO 변환 + List appealCareers = appealCareerRepository.findByStage(stage); + List appealCareerDTOs = StageConverter.toAppealCareerDTOs(appealCareers); + + return GetDocumentStageResponse.from(stage, selfIntroDTOs, appealCareerDTOs); } + @Transactional public GetMidStageResponse getMidStage(Long userId, Long scheduleId, Long stageId) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findByScheduleAndStageIdAndType(schedule, stageId, Type.MID) - .orElseThrow(() -> new NotFoundException(MID_STAGE_NOT_FOUND_EXCEPTION)); - + User user = getUser(userId); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = getStage(stageId, schedule); Optional midReview = midReviewRepository.findByStage(stage); - if(midReview.isEmpty()) { - return new GetMidStageResponse( - true, - null - ); - } - else { - MidReviewDTO midReviewDTO = new MidReviewDTO( - midReview.get().getMidReviewId(), - midReview.get().getFreeReview(), - midReview.get().getGoal() - ); - return new GetMidStageResponse( - false, - midReviewDTO - ); - } + return midReview + .map(review -> new GetMidStageResponse(false, MidReviewDTO.from(review))) + .orElseGet(() -> new GetMidStageResponse(true, null)); } + @Transactional public GetInterviewStageResponse getInterviewStage(Long userId, Long scheduleId, Long stageId) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) + User user = getUser(userId); + Schedule schedule = getSchedule(scheduleId, user); + Stage stage = getStage(stageId, schedule); + + // AppealCareerDTO 변환 + List appealCareers = appealCareerRepository.findByStage(stage); + List appealCareerDTOs = StageConverter.toAppealCareerDTOs(appealCareers); + + // IntReviewDTO 변환 + Optional intReviewDTO = intReviewRepository.findByStage(stage) + .map(IntReviewDTO::from); + + return new GetInterviewStageResponse(intReviewDTO.isEmpty(), intReviewDTO.orElse(null), appealCareerDTOs); + } + + private Stage getStage(Long stageId, Schedule schedule) { + return stageRepository.findByStageIdAndSchedule(stageId, schedule) + .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); + } + + private int calculateDday(LocalDate deadline) { + int dday = Period.between(LocalDate.now(), deadline).getDays(); + return dday; + } + + + private Schedule getSchedule(Long scheduleId, User user) { + return scheduleRepository.findByUserAndScheduleId(user, scheduleId) .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findByScheduleAndStageIdAndType(schedule, stageId, Type.INT) - .orElseThrow(() -> new NotFoundException(INT_STAGE_NOT_FOUND_EXCEPTION)); - - List appealCareerDTOs = appealCareerRepository.findByStage(stage).stream() - .map(appealCareer -> new AppealCareerDTO( - appealCareer.getCareer().getCareerId(), - appealCareer.getCareer().getCategory().getValue(), - appealCareer.getCareer().getTitle() - )) - .toList(); - - Optional intReview = intReviewRepository.findByStage(stage); - - return new GetInterviewStageResponse( - !intReview.isPresent(), - intReview.map(ir -> new IntReviewDTO( - ir.getIntReviewId(), - ir.getMethod(), - ir.getQuestions(), - ir.getFeelings() - )).orElse(null), - appealCareerDTOs - ); } + + private User getUser(Long userId) { + return userRepository.findById(userId) + .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + } + } \ No newline at end of file