Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.moplus.moplus_server.client.problem.dto.response.AllProblemGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ChildProblemClientGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemThumbnailResponse;
import com.moplus.moplus_server.client.problem.dto.response.PublishClientGetResponse;
import com.moplus.moplus_server.client.problem.service.ProblemsGetService;
import com.moplus.moplus_server.global.annotation.AuthUser;
Expand Down Expand Up @@ -65,4 +66,13 @@ public ResponseEntity<ChildProblemClientGetResponse> getChildProblem(
return ResponseEntity.ok(
problemsGetService.getChildProblem(member.getId(), publishId, problemId, childProblemId));
}

@GetMapping("problem/thumbnail/{publishId}/{number}")
@Operation(summary = "문항 썸네일 조회", description = "바로 풀어보기/단계별로 풀어보기 화면에서 필요한 문항을 조회합니다.")
public ResponseEntity<ProblemThumbnailResponse> getProblemThumbnail(
@PathVariable Long publishId,
@PathVariable int number
) {
return ResponseEntity.ok(problemsGetService.getProblemThumbnail(publishId, number));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.moplus.moplus_server.client.problem.dto.response;

import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
import lombok.Builder;

@Builder
public record ProblemThumbnailResponse(
int number,
String imageUrl,
Integer recommendedMinute,
Integer recommendedSecond
) {
public static ProblemThumbnailResponse of(int number, Problem problem) {
return ProblemThumbnailResponse.builder()
.number(number)
.imageUrl(problem.getMainProblemImageUrl())
.recommendedMinute(problem.getRecommendedTime().getMinute())
.recommendedSecond(problem.getRecommendedTime().getSecond())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.moplus.moplus_server.client.problem.dto.response.ChildProblemClientGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemClientGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemFeedProgressesGetResponse;
import com.moplus.moplus_server.client.problem.dto.response.ProblemThumbnailResponse;
import com.moplus.moplus_server.client.problem.dto.response.PublishClientGetResponse;
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmit;
import com.moplus.moplus_server.client.submit.domain.ChildProblemSubmitStatus;
Expand Down Expand Up @@ -214,4 +215,25 @@ private ProblemFeedProgressesGetResponse getProblemStatus(Long memberId, Long pu

return ProblemFeedProgressesGetResponse.of(problemStatus, childProblemStatuses, number);
}

@Transactional(readOnly = true)
public ProblemThumbnailResponse getProblemThumbnail(Long publishId, int number) {
// 발행 조회
Publish publish = publishRepository.findByIdElseThrow(publishId);
denyAccessToFuturePublish(publish);

// 문항 세트 조회
ProblemSet problemSet = problemSetRepository.findByIdElseThrow(publish.getProblemSetId());
List<Long> problemIds = problemSet.getProblemIds();

int index = number - 1;
if (index < 0 || index >= problemIds.size()) {
throw new NotFoundException(ErrorCode.PROBLEM_NUMBER_NOT_FOUND);
}

//문항 조회
Long problemId = problemIds.get(index);
Problem problem = problemRepository.findByIdElseThrow(problemId);
return ProblemThumbnailResponse.of(number, problem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum ErrorCode {
INVALID_CONFIRM_PROBLEM(HttpStatus.BAD_REQUEST, "유효하지 않은 문항들 : "),
INVALID_DIFFICULTY(HttpStatus.BAD_REQUEST, "난이도는 1~10 사이의 숫자여야 합니다"),
PROBLEM_NOT_FOUND_IN_PROBLEM_SET(HttpStatus.NOT_FOUND, "해당 날짜에 발행된 문항세트에 존재하는 문항이 아닙니다."),
PROBLEM_NUMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "번호에 해당하는 문항을 찾을 수 없습니다."),

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