Skip to content

Commit f612ecb

Browse files
committed
[fix/#94] Dto mapper로직 추가
1 parent 68aac4d commit f612ecb

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

src/main/java/com/moplus/moplus_server/client/submit/dto/response/CommentaryGetResponse.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.moplus.moplus_server.client.submit.dto.response;
22

3+
import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
34
import lombok.Builder;
45

56
@Builder
@@ -12,16 +13,14 @@ public record CommentaryGetResponse(
1213
String seniorTipImageUrl,
1314
PrescriptionResponse prescription
1415
) {
15-
public static CommentaryGetResponse of(int problemNumber, String answer, String mainAnalysisImageUrl,
16-
String mainHandwritingExplanationImageUrl, String readingTipImageUrl,
17-
String seniorTipImageUrl, PrescriptionResponse prescription) {
16+
public static CommentaryGetResponse of(int problemNumber, Problem problem, PrescriptionResponse prescription) {
1817
return CommentaryGetResponse.builder()
1918
.problemNumber(problemNumber)
20-
.answer(answer)
21-
.mainAnalysisImageUrl(mainAnalysisImageUrl)
22-
.mainHandwritingExplanationImageUrl(mainHandwritingExplanationImageUrl)
23-
.readingTipImageUrl(readingTipImageUrl)
24-
.seniorTipImageUrl(seniorTipImageUrl)
19+
.answer(problem.getAnswer())
20+
.mainAnalysisImageUrl(problem.getMainAnalysisImageUrl())
21+
.mainHandwritingExplanationImageUrl(problem.getMainHandwritingExplanationImageUrl())
22+
.readingTipImageUrl(problem.getReadingTipImageUrl())
23+
.seniorTipImageUrl(problem.getSeniorTipImageUrl())
2524
.prescription(prescription)
2625
.build();
2726
}

src/main/java/com/moplus/moplus_server/client/submit/dto/response/ProblemDetailResponse.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.moplus.moplus_server.client.submit.dto.response;
22

33
import com.moplus.moplus_server.client.submit.domain.ProblemSubmitStatus;
4+
import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
45
import java.util.List;
56
import lombok.Builder;
67

@@ -10,10 +11,10 @@ public record ProblemDetailResponse(
1011
List<String> prescriptionImageUrls,
1112
ProblemSubmitStatus submitStatus
1213
) {
13-
public static ProblemDetailResponse of(String imageUrl, List<String> prescriptionImageUrls, ProblemSubmitStatus submitStatus) {
14+
public static ProblemDetailResponse of(Problem problem, ProblemSubmitStatus submitStatus) {
1415
return ProblemDetailResponse.builder()
15-
.imageUrl(imageUrl)
16-
.prescriptionImageUrls(prescriptionImageUrls)
16+
.imageUrl(problem.getMainProblemImageUrl())
17+
.prescriptionImageUrls(problem.getPrescriptionImageUrls())
1718
.submitStatus(submitStatus)
1819
.build();
1920
}

src/main/java/com/moplus/moplus_server/client/submit/service/CommentaryGetService.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public CommentaryGetResponse getCommentary(Long publishId, Long problemId) {
4747
// 문항 해설 생성
4848
Problem problem = problemRepository.findByIdElseThrow(problemId);
4949
ProblemDetailResponse mainProblem = ProblemDetailResponse.of(
50-
problem.getMainProblemImageUrl(),
51-
problem.getPrescriptionImageUrls(),
50+
problem,
5251
problemSubmit.getStatus()
5352
);
5453

@@ -74,11 +73,7 @@ public CommentaryGetResponse getCommentary(Long publishId, Long problemId) {
7473

7574
return CommentaryGetResponse.of(
7675
number + 1,
77-
problem.getAnswer(),
78-
problem.getMainAnalysisImageUrl(),
79-
problem.getMainHandwritingExplanationImageUrl(),
80-
problem.getReadingTipImageUrl(),
81-
problem.getSeniorTipImageUrl(),
76+
problem,
8277
prescription
8378
);
8479
}

src/main/java/com/moplus/moplus_server/client/submit/service/ProblemsGetService.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,23 @@ public ChildProblemClientGetResponse getChildProblem(Long publishId, Long proble
137137
ChildProblemSubmit childProblemSubmit = childProblemSubmitRepository.findByMemberIdAndPublishIdAndChildProblemIdElseThrow(
138138
memberId, publishId, childProblemId);
139139

140-
int sequence = 0;
140+
int childProblemNumber = 0;
141141
for (int i = 0; i < problem.getChildProblems().size(); i++) {
142142
if (problem.getChildProblems().get(i).getId().equals(childProblemId)) {
143-
sequence = i + 1;
143+
childProblemNumber = i + 1;
144144
break;
145145
}
146146
}
147147

148-
return ChildProblemClientGetResponse.of(problem.getNumber(), sequence, childProblem.getImageUrl(), childProblemSubmit.getStatus());
148+
// 문항 번호 추출
149+
ProblemSet problemSet = problemSetRepository.findByIdElseThrow(publish.getProblemSetId());
150+
List<Long> problemIds = problemSet.getProblemIds();
151+
int problemNumber = problemIds.indexOf(problemId);
152+
if (problemNumber == -1) {
153+
throw new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND_IN_PROBLEM_SET);
154+
}
155+
156+
return ChildProblemClientGetResponse.of(problemNumber + 1, childProblemNumber + 1, childProblem.getImageUrl(), childProblemSubmit.getStatus());
149157
}
150158

151159
private void denyAccessToFuturePublish(Publish publish){

0 commit comments

Comments
 (0)