-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: applicant 관련 기능에 mapper 도입
- Loading branch information
Showing
15 changed files
with
201 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/server/crews/applicant/dto/response/AnswerResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.server.crews.applicant.dto.response; | ||
|
||
import com.server.crews.recruitment.dto.request.QuestionType; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record AnswerResponse( | ||
Long answerId, | ||
Long questionId, | ||
String content, | ||
Long choiceId, | ||
QuestionType type | ||
) { | ||
} |
39 changes: 7 additions & 32 deletions
39
src/main/java/com/server/crews/applicant/dto/response/ApplicationDetailsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,14 @@ | ||
package com.server.crews.applicant.dto.response; | ||
|
||
import com.server.crews.applicant.domain.Application; | ||
import com.server.crews.applicant.domain.NarrativeAnswer; | ||
import com.server.crews.applicant.domain.SelectiveAnswer; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ApplicationDetailsResponse(Long id, String studentNumber, String major, String name, | ||
List<SelectiveAnswerResponse> selectiveAnswers, | ||
List<NarrativeAnswerResponse> narrativeAnswers) { | ||
|
||
public static ApplicationDetailsResponse of(Application application, List<NarrativeAnswer> narrativeAnswers, | ||
Map<Long, List<SelectiveAnswer>> selectiveAnswers) { | ||
return ApplicationDetailsResponse.builder() | ||
.id(application.getId()) | ||
.studentNumber(application.getStudentNumber()) | ||
.major(application.getMajor()) | ||
.name(application.getName()) | ||
.narrativeAnswers(from(narrativeAnswers)) | ||
.selectiveAnswers(from(selectiveAnswers)) | ||
.build(); | ||
} | ||
|
||
private static List<NarrativeAnswerResponse> from(List<NarrativeAnswer> narrativeAnswers) { | ||
return narrativeAnswers.stream() | ||
.map(NarrativeAnswerResponse::from) | ||
.toList(); | ||
} | ||
|
||
private static List<SelectiveAnswerResponse> from(Map<Long, List<SelectiveAnswer>> selectiveAnswers) { | ||
return selectiveAnswers.entrySet() | ||
.stream() | ||
.map(entry -> SelectiveAnswerResponse.from(entry.getKey(), entry.getValue())) | ||
.toList(); | ||
} | ||
public record ApplicationDetailsResponse( | ||
Long id, | ||
String studentNumber, | ||
String major, | ||
String name, | ||
List<AnswerResponse> answers | ||
) { | ||
} |
18 changes: 7 additions & 11 deletions
18
src/main/java/com/server/crews/applicant/dto/response/ApplicationsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
package com.server.crews.applicant.dto.response; | ||
|
||
import com.server.crews.applicant.domain.Application; | ||
import com.server.crews.applicant.domain.Outcome; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ApplicationsResponse(Long id, String studentNumber, String name, String major, Outcome outcome) { | ||
public static ApplicationsResponse from(final Application application) { | ||
return ApplicationsResponse.builder() | ||
.id(application.getId()) | ||
.studentNumber(application.getStudentNumber()) | ||
.name(application.getName()) | ||
.major(application.getMajor()) | ||
.outcome(application.getOutcome()) | ||
.build(); | ||
} | ||
public record ApplicationsResponse( | ||
Long id, | ||
String studentNumber, | ||
String name, | ||
String major, | ||
Outcome outcome | ||
) { | ||
} |
11 changes: 0 additions & 11 deletions
11
src/main/java/com/server/crews/applicant/dto/response/NarrativeAnswerResponse.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/com/server/crews/applicant/dto/response/SelectedChoiceResponse.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/main/java/com/server/crews/applicant/dto/response/SelectiveAnswerResponse.java
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
src/main/java/com/server/crews/applicant/mapper/AnswerMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.server.crews.applicant.mapper; | ||
|
||
import com.server.crews.applicant.domain.NarrativeAnswer; | ||
import com.server.crews.applicant.domain.SelectiveAnswer; | ||
import com.server.crews.applicant.dto.request.AnswerSaveRequest; | ||
import com.server.crews.applicant.dto.response.AnswerResponse; | ||
import com.server.crews.recruitment.domain.Choice; | ||
import com.server.crews.recruitment.domain.NarrativeQuestion; | ||
import com.server.crews.recruitment.domain.SelectiveQuestion; | ||
import com.server.crews.recruitment.dto.request.QuestionType; | ||
import java.util.List; | ||
|
||
public class AnswerMapper { | ||
|
||
public static AnswerResponse selectiveAnswerToAnswerResponse(SelectiveAnswer selectiveAnswer) { | ||
return AnswerResponse.builder() | ||
.answerId(selectiveAnswer.getId()) | ||
.questionId(selectiveAnswer.getSelectiveQuestion().getId()) | ||
.choiceId(selectiveAnswer.getChoice().getId()) | ||
.type(QuestionType.SELECTIVE) | ||
.build(); | ||
} | ||
|
||
public static AnswerResponse narrativeAnswerToAnswerResponse(NarrativeAnswer narrativeAnswer) { | ||
return AnswerResponse.builder() | ||
.answerId(narrativeAnswer.getId()) | ||
.questionId(narrativeAnswer.getNarrativeQuestion().getId()) | ||
.content(narrativeAnswer.getContent()) | ||
.type(QuestionType.NARRATIVE) | ||
.build(); | ||
} | ||
|
||
public static SelectiveAnswer answerSaveRequestToSelectiveAnswer(AnswerSaveRequest answerSaveRequest) { | ||
return new SelectiveAnswer( | ||
answerSaveRequest.answerId(), | ||
new Choice(answerSaveRequest.choiceId(), null), | ||
new SelectiveQuestion(answerSaveRequest.questionId(), List.of(), null, null, null, null, null)); | ||
} | ||
|
||
public static NarrativeAnswer answerSaveRequestToNarrativeAnswer(AnswerSaveRequest answerSaveRequest) { | ||
return new NarrativeAnswer(answerSaveRequest.answerId(), | ||
new NarrativeQuestion(answerSaveRequest.questionId(), null, null, null, null), | ||
answerSaveRequest.content()); | ||
} | ||
} |
Oops, something went wrong.