Skip to content

Commit

Permalink
[refactor] stage 코드 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
oosedus committed Sep 6, 2024
1 parent 59bed15 commit bd03520
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
);
}
}
Original file line number Diff line number Diff line change
@@ -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<SelfIntroDTO> toSelfIntroDTOs(List<SelfIntro> selfIntros) {
return selfIntros.stream()
.map(SelfIntroDTO::from)
.collect(Collectors.toList());
}

public static List<AppealCareerDTO> toAppealCareerDTOs(List<AppealCareer> appealCareers) {
return appealCareers.stream()
.map(AppealCareerDTO::from)
.collect(Collectors.toList());
}

public static List<StageDTO> toStageDTOs(List<Stage> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,4 +12,12 @@ public record GetDocumentStageResponse(
List<SelfIntroDTO> selfIntroductions,
List<AppealCareerDTO> appealCareers
) {
public static GetDocumentStageResponse from(Stage stage, List<SelfIntroDTO> selfIntroductions, List<AppealCareerDTO> appealCareers) {
return new GetDocumentStageResponse(
stage.getStageId(),
stage.getType().getValue(),
selfIntroductions,
appealCareers
);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,4 +14,16 @@ public record GetStagesResponse(
boolean isAlways,
List<StageDTO> stages
) {

public static GetStagesResponse from(Schedule schedule, List<StageDTO> stages) {
return new GetStagesResponse(
schedule.getScheduleId(),
schedule.getCompany(),
schedule.getDepartment(),
schedule.getUrl(),
schedule.getProgress().getValue(),
schedule.isAlways(),
stages
);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/example/letscareer/stage/domain/model/Stage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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();
}
}
Loading

0 comments on commit bd03520

Please sign in to comment.