Skip to content

Commit

Permalink
Merge pull request #117 from 22caps/dev
Browse files Browse the repository at this point in the history
메 고
  • Loading branch information
GiHoo authored Oct 29, 2024
2 parents df983de + 7bb0354 commit db620ea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
@Repository
public interface ProblemRepository extends JpaRepository<Problem, Long> {

@Query("SELECT p FROM Problem p ORDER BY RAND() LIMIT 1")
Optional<Problem> getRandomProblem();

@Query("SELECT p FROM Problem p WHERE p.problemType = :problemType ORDER BY RAND() LIMIT 1")
Optional<Problem> getProblemByProblemType(ProblemType problemType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public interface ProblemService {

ProblemResponseDto getRandomProblem();

ProblemResponseDto getProblemByProblemType(String problemTypeRequest);

ProblemHintResponseDto getHintByQuestion(Long problemId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ public class ProblemServiceImpl implements ProblemService {
private final ProblemRepository problemRepository;
private final PromptService promptService;

@Override
public ProblemResponseDto getRandomProblem() {
return ProblemResponseDto.of(
problemRepository.getRandomProblem()
.orElseThrow(
() -> ProblemExistsException.of(
ProblemErrorCode.PROBLEM_IS_NOT_EXISTS)));
}

@Override
public ProblemResponseDto getProblemByProblemType(String problemTypeRequest) {
return ProblemResponseDto.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public class ProblemController {

private final ProblemService problemService;

@GetMapping("/random")
@Operation(summary = "랜덤 문제 조회", description = "문제 유형을 통해 랜덤 문제를 조회합니다. 해당 요청은 문제 풀이 시마다 호출됩니다.")
@ApiResponse(responseCode = "200", description = "문제 조회 성공")
public ProblemResponseDto getRandomProblem() {
return problemService.getRandomProblem();
}


@GetMapping("/{problemType}")
@Operation(summary = "문제 조회", description = "문제 유형을 통해 문제를 조회합니다. 해당 요청은 문제 풀이 시마다 호출됩니다.")
@ApiResponse(responseCode = "200", description = "문제 조회 성공")
Expand Down

0 comments on commit db620ea

Please sign in to comment.