Skip to content

Commit d9a583b

Browse files
authored
Merge pull request #105 from team-ppointer/feature/#104
[feat/#104] 문항 썸네일 조회 api
2 parents 0e79e86 + 967b47f commit d9a583b

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/main/java/com/moplus/moplus_server/client/problem/controller/ProblemGetController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.moplus.moplus_server.client.problem.dto.response.AllProblemGetResponse;
44
import com.moplus.moplus_server.client.problem.dto.response.ChildProblemClientGetResponse;
55
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientGetResponse;
6+
import com.moplus.moplus_server.client.problem.dto.response.ProblemThumbnailResponse;
67
import com.moplus.moplus_server.client.problem.dto.response.PublishClientGetResponse;
78
import com.moplus.moplus_server.client.problem.service.ProblemsGetService;
89
import com.moplus.moplus_server.global.annotation.AuthUser;
@@ -65,4 +66,13 @@ public ResponseEntity<ChildProblemClientGetResponse> getChildProblem(
6566
return ResponseEntity.ok(
6667
problemsGetService.getChildProblem(member.getId(), publishId, problemId, childProblemId));
6768
}
69+
70+
@GetMapping("problem/thumbnail/{publishId}/{number}")
71+
@Operation(summary = "문항 썸네일 조회", description = "바로 풀어보기/단계별로 풀어보기 화면에서 필요한 문항을 조회합니다.")
72+
public ResponseEntity<ProblemThumbnailResponse> getProblemThumbnail(
73+
@PathVariable Long publishId,
74+
@PathVariable int number
75+
) {
76+
return ResponseEntity.ok(problemsGetService.getProblemThumbnail(publishId, number));
77+
}
6878
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.moplus.moplus_server.client.problem.dto.response;
2+
3+
import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
4+
import lombok.Builder;
5+
6+
@Builder
7+
public record ProblemThumbnailResponse(
8+
int number,
9+
String imageUrl,
10+
Integer recommendedMinute,
11+
Integer recommendedSecond
12+
) {
13+
public static ProblemThumbnailResponse of(int number, Problem problem) {
14+
return ProblemThumbnailResponse.builder()
15+
.number(number)
16+
.imageUrl(problem.getMainProblemImageUrl())
17+
.recommendedMinute(problem.getRecommendedTime().getMinute())
18+
.recommendedSecond(problem.getRecommendedTime().getSecond())
19+
.build();
20+
}
21+
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.moplus.moplus_server.client.problem.dto.response.ChildProblemClientGetResponse;
77
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientGetResponse;
88
import com.moplus.moplus_server.client.problem.dto.response.ProblemFeedProgressesGetResponse;
9+
import com.moplus.moplus_server.client.problem.dto.response.ProblemThumbnailResponse;
910
import com.moplus.moplus_server.client.problem.dto.response.PublishClientGetResponse;
1011
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmit;
1112
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmitStatus;
@@ -214,4 +215,25 @@ private ProblemFeedProgressesGetResponse getProblemStatus(Long memberId, Long pu
214215

215216
return ProblemFeedProgressesGetResponse.of(problemStatus, childProblemStatuses, number);
216217
}
218+
219+
@Transactional(readOnly = true)
220+
public ProblemThumbnailResponse getProblemThumbnail(Long publishId, int number) {
221+
// 발행 조회
222+
Publish publish = publishRepository.findByIdElseThrow(publishId);
223+
denyAccessToFuturePublish(publish);
224+
225+
// 문항 세트 조회
226+
ProblemSet problemSet = problemSetRepository.findByIdElseThrow(publish.getProblemSetId());
227+
List<Long> problemIds = problemSet.getProblemIds();
228+
229+
int index = number - 1;
230+
if (index < 0 || index >= problemIds.size()) {
231+
throw new NotFoundException(ErrorCode.PROBLEM_NUMBER_NOT_FOUND);
232+
}
233+
234+
//문항 조회
235+
Long problemId = problemIds.get(index);
236+
Problem problem = problemRepository.findByIdElseThrow(problemId);
237+
return ProblemThumbnailResponse.of(number, problem);
238+
}
217239
}

src/main/java/com/moplus/moplus_server/global/error/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum ErrorCode {
3535
INVALID_CONFIRM_PROBLEM(HttpStatus.BAD_REQUEST, "유효하지 않은 문항들 : "),
3636
INVALID_DIFFICULTY(HttpStatus.BAD_REQUEST, "난이도는 1~10 사이의 숫자여야 합니다"),
3737
PROBLEM_NOT_FOUND_IN_PROBLEM_SET(HttpStatus.NOT_FOUND, "해당 날짜에 발행된 문항세트에 존재하는 문항이 아닙니다."),
38+
PROBLEM_NUMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "번호에 해당하는 문항을 찾을 수 없습니다."),
3839

3940
//새끼 문항
4041
CHILD_PROBLEM_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 새끼 문제를 찾을 수 없습니다"),

0 commit comments

Comments
 (0)