Skip to content

Commit

Permalink
Merge pull request #30 from Triumers/user
Browse files Browse the repository at this point in the history
[Refactor] Solved userId token 이용 처리
  • Loading branch information
noctesilente authored Apr 16, 2024
2 parents 9e1520c + f0860bb commit fcbda63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public interface AuthService {
void modifyPassword(PasswordDTO passwordDTO) throws WrongPasswordException, WrongInputTypeException;

void updateSolvedQuiz(boolean isCorrect);

public int getUserId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public void updateSolvedQuiz(boolean isCorrect) {
userRepository.save(user);
}

@Override
public int getUserId() {
return userRepository.findByEmail(SecurityContextHolder.getContext().getAuthentication().getName()).getId();
}

private User userMapper(AuthDTO request) {
User user = new User();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SolvedDTO findSelectedOptionAndCompareAnswer(SolvedRequest solvedRequest)

modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);

int userId = solvedRequest.getUserId();
int userId = authService.getUserId();
int quizId = solvedRequest.getQuizId();
String seletedOption = solvedRequest.getSelectedOption();

Expand Down Expand Up @@ -87,7 +87,7 @@ public List<Solved> findSolvedQuizListByUserId(SolvedRequest solvedRequest) {
/* 설명. 사용자의 ID와 문제 ID로 문제 내용 불러오기 */
@Override
public SolvedDTO findSolvedQuizByUserIdAndQuizId(SolvedRequest solvedRequest) {
int userId = solvedRequest.getUserId();
int userId = authService.getUserId();
int quizId = solvedRequest.getQuizId();

Solved solvedQuiz = solvedRepository.findSelectedOptionByUserIdAndQuizId(userId, quizId);
Expand Down Expand Up @@ -118,7 +118,7 @@ public SolvedDTO findSolvedQuizByUserIdAndQuizId(SolvedRequest solvedRequest) {

@Override
public List<Solved> findCorrectQuizByUserIdAndSolvedDate(SolvedResultRequest solvedResultRequest) {
int userId = solvedResultRequest.getUserId();
int userId = authService.getUserId();
boolean isCorrect = solvedResultRequest.isCorrect();
LocalDate solvedDate = solvedResultRequest.getSolvedDate();

Expand All @@ -129,8 +129,7 @@ public List<Solved> findCorrectQuizByUserIdAndSolvedDate(SolvedResultRequest sol

@Override
public List<SolvedDTO> findSolvedQuizListByUserIdAndDate(SolvedRequest solvedRequest) {
System.out.println(solvedRequest);
int userId = solvedRequest.getUserId();
int userId = authService.getUserId();
LocalDate solvedDate = solvedRequest.getSolvedDate();

List<Solved> solvedList = solvedRepository.findSolvedQuizByUserIdAndSolvedDate(userId, solvedDate);
Expand Down Expand Up @@ -161,6 +160,4 @@ public List<SolvedDTO> findSolvedQuizListByUserIdAndDate(SolvedRequest solvedReq

return solvedDTOList;
}


}

0 comments on commit fcbda63

Please sign in to comment.