-
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.
Merge pull request #59 from GPGT-Algorithm-Study/develop
[FEAT] 크론잡 실패 시 Retry 기능 추가
- Loading branch information
Showing
10 changed files
with
171 additions
and
4 deletions.
There are no files selected for viewing
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
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
23 changes: 23 additions & 0 deletions
23
.../com/randps/randomdefence/domain/statistics/controller/RecentSolvedProblemController.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,23 @@ | ||
package com.randps.randomdefence.domain.statistics.controller; | ||
|
||
import com.randps.randomdefence.domain.statistics.dto.RecentlyTodaySolvedProblemResponseDto; | ||
import com.randps.randomdefence.domain.statistics.service.RecentSolvedProblemService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/stat/recent-solved-problem") | ||
public class RecentSolvedProblemController { | ||
|
||
private final RecentSolvedProblemService recentSolvedProblemService; | ||
|
||
@GetMapping("/today") | ||
public List<RecentlyTodaySolvedProblemResponseDto> getTodayRecentSolvedProblems() { | ||
return recentSolvedProblemService.getTodayRecentSolvedProblems(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...com/randps/randomdefence/domain/statistics/dto/RecentlyTodaySolvedProblemResponseDto.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,36 @@ | ||
package com.randps.randomdefence.domain.statistics.dto; | ||
|
||
import com.randps.randomdefence.domain.problem.dto.ProblemDto; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class RecentlyTodaySolvedProblemResponseDto { | ||
|
||
private LocalDateTime solvedAt; | ||
|
||
private String bojHandle; | ||
|
||
private String notionId; | ||
|
||
private String profileImg; | ||
|
||
private String emoji; | ||
|
||
private ProblemDto problem; | ||
|
||
@Builder | ||
public RecentlyTodaySolvedProblemResponseDto(LocalDateTime solvedAt, String bojHandle, String notionId, String profileImg, String emoji, ProblemDto problem) { | ||
this.solvedAt = solvedAt; | ||
this.bojHandle = bojHandle; | ||
this.notionId = notionId; | ||
this.profileImg = profileImg; | ||
this.emoji = emoji; | ||
this.problem = problem; | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...n/java/com/randps/randomdefence/domain/statistics/service/RecentSolvedProblemService.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,57 @@ | ||
package com.randps.randomdefence.domain.statistics.service; | ||
|
||
import com.randps.randomdefence.domain.problem.service.ProblemService; | ||
import com.randps.randomdefence.domain.statistics.dto.RecentlyTodaySolvedProblemResponseDto; | ||
import com.randps.randomdefence.domain.user.domain.User; | ||
import com.randps.randomdefence.domain.user.domain.UserSolvedProblem; | ||
import com.randps.randomdefence.domain.user.service.port.UserRepository; | ||
import com.randps.randomdefence.domain.user.service.port.UserSolvedProblemRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.transaction.Transactional; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class RecentSolvedProblemService { | ||
|
||
private final UserSolvedProblemRepository userSolvedProblemRepository; | ||
|
||
private final ProblemService problemService; | ||
|
||
private final UserRepository userRepository; | ||
|
||
/* | ||
* 오늘 해결된 문제를 최신순으로 가져온다. | ||
*/ | ||
@Transactional | ||
public List<RecentlyTodaySolvedProblemResponseDto> getTodayRecentSolvedProblems() { | ||
|
||
// 오늘 해결된 문제들을 가져온다. | ||
List<UserSolvedProblem> todaySolvedProblems = userSolvedProblemRepository.findAllTodaySolvedProblem(); | ||
|
||
// 문제들을 최신순으로 정렬한다. | ||
todaySolvedProblems.sort((a, b) -> b.getCreatedDate().compareTo(a.getCreatedDate())); | ||
|
||
// 문제들을 최신순으로 정렬한 후, 최신순으로 정렬된 문제들을 RecentlyTodaySolvedProblemResponseDto로 변환한다. | ||
List<RecentlyTodaySolvedProblemResponseDto> results = new ArrayList<>(); | ||
for (UserSolvedProblem userSolvedProblem : todaySolvedProblems) { | ||
User user = userRepository.findByBojHandle(userSolvedProblem.getBojHandle()) | ||
.orElseThrow(() -> new IllegalArgumentException("해당하는 유저가 없습니다.")); | ||
|
||
RecentlyTodaySolvedProblemResponseDto userSolvedDto = RecentlyTodaySolvedProblemResponseDto.builder() | ||
.solvedAt(userSolvedProblem.getCreatedDate()) | ||
.bojHandle(user.getBojHandle()) | ||
.notionId(user.getNotionId()) | ||
.profileImg(user.getProfileImg()) | ||
.emoji(user.getEmoji()) | ||
.problem(problemService.findProblem(userSolvedProblem.getProblemId())) | ||
.build(); | ||
results.add(userSolvedDto); | ||
} | ||
|
||
return results; | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
...a/com/randps/randomdefence/domain/user/infrastructure/UserSolvedProblemJpaRepository.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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package com.randps.randomdefence.domain.user.infrastructure; | ||
|
||
import com.randps.randomdefence.domain.user.domain.UserSolvedProblem; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserSolvedProblemJpaRepository extends JpaRepository<UserSolvedProblem, Long> { | ||
List<UserSolvedProblem> findAllByBojHandle(String bojHandle); | ||
|
||
Optional<UserSolvedProblem> findByBojHandleAndProblemId(String bojHandle, Integer problemId); | ||
|
||
List<UserSolvedProblem> findAllByCreatedDateAfter(LocalDateTime createdDate); | ||
|
||
void deleteAllByBojHandle(String bojHandle); | ||
} |
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
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
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
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