Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fing9 committed Dec 6, 2023
2 parents 936e097 + aca84cc commit 2ae5be7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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);
}
}
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);
}

}

0 comments on commit 2ae5be7

Please sign in to comment.