Skip to content

Commit

Permalink
Feat: 8월 4주차 랭킹 수동 반영 (#153)
Browse files Browse the repository at this point in the history
- 매주 월요일 18시에 기본으로 진행되지만, 이번 주만 월, 화요일을
  바탕으로 주간 랭킹 생성
  • Loading branch information
emes-g authored Aug 20, 2024
1 parent afaa598 commit cf16ea5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/main/java/store/itpick/backend/util/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public static LocalDate getMondayOfPreviousWeek() {
return aWeekAgo.minusDays(diffFromMonday);
}

public static LocalDate getMondayOfThisWeek() {
LocalDate thisWeek = LocalDate.now();
int diffFromMonday = thisWeek.getDayOfWeek().getValue() - 1; // 월요일 0, 화요일 1, ..., 일요일 6
return thisWeek.minusDays(diffFromMonday);
}

public static LocalDate stringToLocalDate(String date) {
int year = Integer.parseInt("20" + date.substring(0, 2));
int month = Integer.parseInt(date.substring(2, 4));
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/store/itpick/backend/util/Redis.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ public void saveDay() {
public void saveWeek() {
ZSetOperations<String, Object> zSetOperations = redisTemplate.opsForZSet();

LocalDate mondayOfPreviousWeek = DateUtils.getMondayOfPreviousWeek(); // 지난주 월요일
// LocalDate mondayOfPreviousWeek = DateUtils.getMondayOfPreviousWeek(); // 지난주 월요일
LocalDate mondayOfPreviousWeek = DateUtils.getMondayOfThisWeek(); // 이번주 월요일
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyMMdd");
List<List<String>> dayKeyListOfPreviousWeek = new ArrayList<>();
for (int i = 0; i < 7; i++) {
for (int i = 0; i < 2; i++) { // 월, 화만
LocalDate dayOfPreviousWeek = mondayOfPreviousWeek.plusDays(i); // 지난주 월요일부터 일요일까지

// 해당 날짜의 모든 커뮤니티의 키를 담고 있는 리스트
Expand Down Expand Up @@ -97,7 +98,8 @@ public void saveTotalRanking(PeriodType periodType) {
String date = switch (periodType) {
case BY_REAL_TIME -> "not needed";
case BY_DAY -> DateUtils.localDateToString(LocalDate.now());
case BY_WEEK -> DateUtils.localDateToString(DateUtils.getMondayOfPreviousWeek());
// case BY_WEEK -> DateUtils.localDateToString(DateUtils.getMondayOfPreviousWeek());
case BY_WEEK -> DateUtils.localDateToString(DateUtils.getMondayOfThisWeek());
};
String totalKey = makeKey(CommunityType.TOTAL, periodType, date);
redisTemplate.delete(totalKey); // (혹시 존재했을지 모르는) 기존 키 삭제
Expand Down

0 comments on commit cf16ea5

Please sign in to comment.