-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...randomdefence/domain/recommendation/controller/RecommendationAlreadySolvedController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.randps.randomdefence.domain.recommendation.controller; | ||
|
||
import com.randps.randomdefence.domain.problem.dto.ProblemSolveJudgedDto; | ||
import com.randps.randomdefence.domain.recommendation.service.RecommendationAlreadySolvedService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/recommend/solved") | ||
public class RecommendationAlreadySolvedController { | ||
|
||
private final RecommendationAlreadySolvedService recommendationAlreadySolvedService; | ||
|
||
/* | ||
* 유저가 기존에 푼 문제중 하나를 랜덤하게 뽑아온다. | ||
*/ | ||
@GetMapping("/") | ||
public ProblemSolveJudgedDto getSolvedProblemRandom(@Param("bojHandle") String bojHandle) { | ||
return recommendationAlreadySolvedService.findOneRandomSolvedProblem(bojHandle); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...andps/randomdefence/domain/recommendation/service/RecommendationAlreadySolvedService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.randps.randomdefence.domain.recommendation.service; | ||
|
||
import com.randps.randomdefence.domain.problem.dto.ProblemDto; | ||
import com.randps.randomdefence.domain.problem.dto.ProblemSolveJudgedDto; | ||
import com.randps.randomdefence.domain.problem.service.ProblemService; | ||
import com.randps.randomdefence.domain.user.domain.UserAlreadySolved; | ||
import com.randps.randomdefence.domain.user.domain.UserAlreadySolvedRepository; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import javax.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class RecommendationAlreadySolvedService { | ||
|
||
private final ProblemService problemService; | ||
|
||
private final UserAlreadySolvedRepository userAlreadySolvedRepository; | ||
|
||
@Transactional | ||
public ProblemSolveJudgedDto findOneRandomSolvedProblem(String bojHandle) { | ||
UserAlreadySolved userAlreadySolved = userAlreadySolvedRepository.findByBojHandle(bojHandle).orElseThrow(() -> new NoSuchElementException("유저가 기존에 푼 문제가 존재하지 않습니다.")); | ||
List<Integer> solvedProblems = userAlreadySolved.getAlreadySolvedList(); | ||
ProblemDto problemDto = problemService.findProblem(solvedProblems.get((int)Math.round(Math.random() * (solvedProblems.size() - 1)))); | ||
return new ProblemSolveJudgedDto(problemDto, true); | ||
} | ||
|
||
} |