20
20
import com .moplus .moplus_server .domain .problem .domain .problem .Problem ;
21
21
import com .moplus .moplus_server .domain .problem .repository .ChildProblemRepository ;
22
22
import com .moplus .moplus_server .domain .problem .repository .ProblemRepository ;
23
+ import com .moplus .moplus_server .domain .problemset .domain .ProblemSet ;
23
24
import com .moplus .moplus_server .domain .problemset .repository .ProblemSetRepository ;
24
25
import com .moplus .moplus_server .domain .publish .repository .PublishRepository ;
25
26
import com .moplus .moplus_server .global .error .exception .ErrorCode ;
26
27
import com .moplus .moplus_server .global .error .exception .InvalidValueException ;
28
+ import com .moplus .moplus_server .global .error .exception .NotFoundException ;
27
29
import java .time .LocalDate ;
28
30
import java .util .ArrayList ;
29
31
import java .util .List ;
32
+ import javax .swing .undo .CannotUndoException ;
30
33
import lombok .RequiredArgsConstructor ;
31
34
import org .springframework .stereotype .Service ;
32
35
import org .springframework .transaction .annotation .Transactional ;
@@ -74,8 +77,16 @@ public CommentaryGetResponse getCommentary(Long publishId, Long problemId) {
74
77
// 처방 정보 생성
75
78
PrescriptionResponse prescription = PrescriptionResponse .of (childProblem , mainProblem );
76
79
80
+ // 문항 번호 추출
81
+ ProblemSet problemSet = problemSetRepository .findByIdElseThrow (publish .getProblemSetId ());
82
+ List <Long > problemIds = problemSet .getProblemIds ();
83
+ int number = problemIds .indexOf (problemId );
84
+ if (number == -1 ) {
85
+ throw new NotFoundException (ErrorCode .PROBLEM_NOT_FOUND_IN_PROBLEM_SET );
86
+ }
87
+
77
88
return CommentaryGetResponse .of (
78
- problem . getNumber () ,
89
+ number + 1 ,
79
90
problem .getAnswer (),
80
91
problem .getMainAnalysisImageUrl (),
81
92
problem .getMainHandwritingExplanationImageUrl (),
@@ -138,6 +149,14 @@ public ProblemClientGetResponse getProblem(Long publishId, Long problemId) {
138
149
Publish publish = publishRepository .findByIdElseThrow (publishId );
139
150
denyAccessToFuturePublish (publish );
140
151
152
+ // 문항 번호 추출
153
+ ProblemSet problemSet = problemSetRepository .findByIdElseThrow (publish .getProblemSetId ());
154
+ List <Long > problemIds = problemSet .getProblemIds ();
155
+ int number = problemIds .indexOf (problemId );
156
+ if (number == -1 ) {
157
+ throw new NotFoundException (ErrorCode .PROBLEM_NOT_FOUND_IN_PROBLEM_SET );
158
+ }
159
+
141
160
// 문항조회
142
161
Problem problem = problemRepository .findByIdElseThrow (problemId );
143
162
@@ -155,7 +174,7 @@ public ProblemClientGetResponse getProblem(Long publishId, Long problemId) {
155
174
.map (ChildProblemSubmit ::getStatus )
156
175
.toList ();
157
176
158
- return ProblemClientGetResponse .of (problem , problemSubmit .getStatus (), childProblemStatuses );
177
+ return ProblemClientGetResponse .of (problem , problemSubmit .getStatus (), childProblemStatuses , number + 1 );
159
178
}
160
179
161
180
@ Transactional (readOnly = true )
0 commit comments