Skip to content

Commit

Permalink
Merge pull request #59 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 9879e6e + aaae2be commit 8f0027c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,21 @@ public ApiResponse<List<Quiz>> getQuizToLevelTest(HttpServletRequest request, Ht
return ApiResponse.onFailure("400", "ํ€ด์ฆˆ ๋‚ด์šฉ์„ ์ œ๋Œ€๋กœ ๊ฐ€์ ธ์˜ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค", quiz);
}

@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/result")
public ApiResponse<QuizResponseDTO.quizResultResponseDTO> getQuizLevelResult(@RequestParam int score, HttpServletRequest request, HttpServletResponse response){
Users user = usersService.getUserIdByToken(request, response);
QuizResponseDTO.quizResultResponseDTO quizLevelResult = quizService.getQuizLevelResult(user.getId(), score);
return ApiResponse.onSuccess(quizLevelResult);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.finut.finut_server.domain.quiz;

import com.finut.finut_server.domain.difficulty.DifficultyType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import com.finut.finut_server.domain.level.LevelName;
import lombok.*;
import org.apache.commons.lang3.builder.Diff;

public class QuizResponseDTO {

Expand All @@ -19,4 +18,13 @@ public static class randomQuizResponseDTO {
AnswerType answer;
String description;
}

@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class quizResultResponseDTO {
String difficulty;
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/finut/finut_server/service/QuizService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.finut.finut_server.service;

import com.finut.finut_server.domain.difficulty.Difficulty;
import com.finut.finut_server.domain.difficulty.DifficultyType;
import com.finut.finut_server.domain.level.Level;
import com.finut.finut_server.domain.quiz.Quiz;
import com.finut.finut_server.domain.quiz.QuizRepository;
import com.finut.finut_server.domain.quiz.QuizResponseDTO;
import com.finut.finut_server.domain.quizDone.QuizDoneRepository;
import com.finut.finut_server.domain.user.Users;
import com.finut.finut_server.domain.user.UsersRepository;
Expand Down Expand Up @@ -80,6 +83,27 @@ public List<Quiz> getQuizToLevelTest(Long userId) {
return uncompletedQuizzes;
}

@Transactional
public QuizResponseDTO.quizResultResponseDTO getQuizLevelResult(Long userId, int score) {
Users users = usersRepository.findById(userId).orElseThrow(() -> new RuntimeException("User not found"));
Difficulty difficulty = new Difficulty();
QuizResponseDTO.quizResultResponseDTO quizResultResponseDTO = new QuizResponseDTO.quizResultResponseDTO();
if(score >= 20){
difficulty.setDifficulty(DifficultyType.HI);
users.setDifficulty(difficulty);
quizResultResponseDTO.setDifficulty("HIGH");
} else if(score >= 9){
difficulty.setDifficulty(DifficultyType.MI);
users.setDifficulty(difficulty);
quizResultResponseDTO.setDifficulty("MIDDLE");
}
else{
quizResultResponseDTO.setDifficulty("LOW");
}
usersRepository.save(users);
return quizResultResponseDTO;
}

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

Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/finut/finut_server/service/UsersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ public UserResponseDTO.updateAttendance updateAttendDate(Long userId){
msg = "์—ฐ์† 5ํšŒ ์ถœ์„ํ–ˆ์Šต๋‹ˆ๋‹ค!";
}

// XP๊ฐ€ 100์ด๋ฉด ์Šน์ง„ํ•˜๊ธฐ
if(user.getXP() >= 100){
user.setXP(user.getXP() - 100);
Long newLevelId = user.getLevel().getId() + 1L; // id์— 1 ์ฆ๊ฐ€

// ์ฆ๊ฐ€๋œ id๋ฅผ ๊ฐ€์ง„ Level ์—”ํ‹ฐํ‹ฐ๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์กฐํšŒํ•˜์—ฌ user์— ์„ค์ •
Level newLevel = levelRepository.findById(newLevelId)
.orElseThrow(() -> new IllegalArgumentException("์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ ˆ๋ฒจ์ž…๋‹ˆ๋‹ค."));
user.setLevel(newLevel); // user์— ์ƒˆ๋กœ์šด Level ์„ค์ •
msg = "์Šน์ง„ํ–ˆ์Šต๋‹ˆ๋‹ค!";
}
// // XP๊ฐ€ 100์ด๋ฉด ์Šน์ง„ํ•˜๊ธฐ
// if(user.getXP() >= 100){
// user.setXP(user.getXP() - 100);
// Long newLevelId = user.getLevel().getId() + 1L; // id์— 1 ์ฆ๊ฐ€
//
// // ์ฆ๊ฐ€๋œ id๋ฅผ ๊ฐ€์ง„ Level ์—”ํ‹ฐํ‹ฐ๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์กฐํšŒํ•˜์—ฌ user์— ์„ค์ •
// Level newLevel = levelRepository.findById(newLevelId)
// .orElseThrow(() -> new IllegalArgumentException("์กด์žฌํ•˜์ง€ ์•Š๋Š” ๋ ˆ๋ฒจ์ž…๋‹ˆ๋‹ค."));
// user.setLevel(newLevel); // user์— ์ƒˆ๋กœ์šด Level ์„ค์ •
// msg = "์Šน์ง„ํ–ˆ์Šต๋‹ˆ๋‹ค!";
// }

usersRepository.save(user);
}
Expand Down

0 comments on commit 8f0027c

Please sign in to comment.