Skip to content

Commit

Permalink
Merge pull request #55 from devocean-finut/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
plum-king authored Nov 14, 2024
2 parents 5e5fe37 + fc7b84b commit f41f5b2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Optional;

@RestController
Expand Down Expand Up @@ -74,7 +75,7 @@ public ApiResponse<Optional<Quiz>> getQuiz(HttpServletRequest request, HttpServl
@Operation(summary = "퀴즈를 맞췄을 때", description = "퀴즈를 맞췄을 때 QuizDone DB에 해당 내용을 저장하고, 난이도 상승에 필요한 퀴즈 개수와 레벨업에 필요한 XP를 증가시킵니다.")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "성공", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = String.class))),
schema = @Schema(implementation = UserResponseDTO.checkUserXP.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "퀴즈 내용을 제대로 가지고 오지 못했습니다.",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 에러, 관리자에게 문의 바랍니다.",
Expand Down Expand Up @@ -131,4 +132,23 @@ public ApiResponse<String> quizWrong(@PathVariable Long quizId, HttpServletReque
}
}

@Operation(summary = "레벨 테스트 조회", description = "레벨 테스트를 위한 퀴즈 조회 API")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "성공", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Quiz.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "400", description = "퀴즈 내용을 제대로 가지고 오지 못했습니다.",
content = @Content),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 에러, 관리자에게 문의 바랍니다.",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorReasonDTO.class)))
})
@GetMapping("/level")
public ApiResponse<List<Quiz>> getQuizToLevelTest(HttpServletRequest request, HttpServletResponse response){
Users user = usersService.getUserIdByToken(request, response);
List<Quiz> quiz = quizService.getQuizToLevelTest(user.getId());
if(!quiz.isEmpty())
return ApiResponse.onSuccess(quiz);
return ApiResponse.onFailure("400", "퀴즈 내용을 제대로 가져오지 못했습니다", quiz);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@
public interface QuizRepository extends JpaRepository<Quiz, Long> {

List<Quiz> findByDifficulty(DifficultyType quizDiff);
@Query(value = "(SELECT * FROM quiz WHERE difficulty = 'HI' ORDER BY RAND() LIMIT 3) " +
"UNION ALL " +
"(SELECT * FROM quiz WHERE difficulty = 'LO' ORDER BY RAND() LIMIT 3) " +
"UNION ALL " +
"(SELECT * FROM quiz WHERE difficulty = 'MI' ORDER BY RAND() LIMIT 3)",
nativeQuery = true)
List<Quiz> findQuizzesByDifficulty();
}
12 changes: 12 additions & 0 deletions src/main/java/com/finut/finut_server/service/QuizService.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ public Optional<Quiz> getQuiz(Long userId) {
return Optional.of(uncompletedQuizzes.get(random.nextInt(uncompletedQuizzes.size())));
}

@Transactional
public List<Quiz> getQuizToLevelTest(Long userId) {
Optional<Users> userOpt = usersRepository.findById(userId);
if (userOpt.isEmpty()) {
System.out.println("userOpt is empty");
return null;
}
// 퀴즈 목록 생성
List<Quiz> uncompletedQuizzes = quizRepository.findQuizzesByDifficulty();

return uncompletedQuizzes;
}

public Optional<Quiz> getQuizByQuizId(Long quizId) {
return quizRepository.findById(quizId);
Expand Down

0 comments on commit f41f5b2

Please sign in to comment.