From 904f2e10769d8cf0d8d607aa7e0a1102c1d1d760 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 20:53:59 +0900 Subject: [PATCH 1/9] =?UTF-8?q?chore:=20=EB=AF=B8=EB=9E=98=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=20=EC=9E=85=EB=A0=A5=20=EB=AA=BB=EB=B0=9B=EA=B2=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anniversary/service/AnniversaryService.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java index 61fc2fc..544c32d 100644 --- a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java +++ b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java @@ -40,6 +40,12 @@ public Anniversary addAnniversary(Long memberId, AnniversaryRequestDTO requestDT throw new IllegalArgumentException("Invalid anniversary type"); } + LocalDate requestDate = requestDTO.getDate(); + LocalDate currentDate = LocalDate.now(ZoneId.of("UTC")); + if (requestDate.isAfter(currentDate)) { + throw new IllegalArgumentException("Date cannot be in the future"); + } + ZonedDateTime zonedDateTime = requestDTO.getDate().atStartOfDay(ZoneId.of("UTC")); Timestamp timestamp = Timestamp.from(zonedDateTime.toInstant()); @@ -63,6 +69,12 @@ public Anniversary updateAnniversary(Long memberId, Long anniversaryId, Annivers validateAnniversaryType(requestDTO.getType()); + LocalDate requestDate = requestDTO.getDate(); + LocalDate currentDate = LocalDate.now(ZoneId.of("UTC")); + if (requestDate.isAfter(currentDate)) { + throw new IllegalArgumentException("Date cannot be in the future"); + } + ZonedDateTime zonedDateTime = requestDTO.getDate().atStartOfDay(ZoneId.of("UTC")); Timestamp timestamp = Timestamp.from(zonedDateTime.toInstant()); From 68ac9deac61910f79f75b4d9bcf4683b93c5daf4 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 21:29:44 +0900 Subject: [PATCH 2/9] =?UTF-8?q?chore:=20=EA=B8=B0=EB=85=90=EC=9D=BC=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=EA=B0=92=201=EA=B0=9C=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/AnniversaryService.java | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java index 544c32d..5a87349 100644 --- a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java +++ b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java @@ -114,44 +114,32 @@ public List> calculateDDay(Anniversary anniversary) { int daysPassed = (int) ChronoUnit.DAYS.between(anniversaryDate, today); int nextDay = ((daysPassed / 100) + 1) * 100; - for (int i = 0; i < 2; i++) { + for (int i = 0; i < 1; i++) { LocalDate hundredDays = anniversaryDate.plusDays(nextDay + i * 100); if (!hundredDays.isBefore(today)) { Map dDay = new HashMap<>(); - dDay.put((nextDay + i * 100) + "days", (int) ChronoUnit.DAYS.between(today, hundredDays) - 1); + dDay.put((nextDay + i * 100) + "days", (int) ChronoUnit.DAYS.between(today, hundredDays)); dDayList.add(dDay); + return dDayList; } } } - boolean isTodayAnniversary = false; + for (int i = 1; i <= yearsDifference + 1; i++) { LocalDate yearAnniversary = anniversaryDate.plusYears(i); - int daysBetween = (int) ChronoUnit.DAYS.between(today, yearAnniversary); - if (daysBetween == 0) { + if (!yearAnniversary.isBefore(today)) { Map dDay = new HashMap<>(); - dDay.put("year", daysBetween); + dDay.put("year", (int) ChronoUnit.DAYS.between(today, yearAnniversary)); dDayList.add(dDay); - isTodayAnniversary = true; - break; - } - } - - if (!isTodayAnniversary) { - for (int i = 1; i <= yearsDifference + 1; i++) { - LocalDate yearAnniversary = anniversaryDate.plusYears(i); - if (!yearAnniversary.isBefore(today)) { - Map dDay = new HashMap<>(); - dDay.put("year", (int) ChronoUnit.DAYS.between(today, yearAnniversary)); - dDayList.add(dDay); - break; - } + return dDayList; } } return dDayList; } + public List getDDayZeroAnniversaries(List anniversaries) { List dDayZeroList = new ArrayList<>(); From f9f77dde51f2b58b415ec1b8b151b2ccabb6a6d5 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 21:48:13 +0900 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20100=EC=9D=BC=20=EC=A3=BC=EA=B8=B0=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20=EA=B0=92=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fiurinee/domain/anniversary/service/AnniversaryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java index 5a87349..e7baa08 100644 --- a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java +++ b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java @@ -118,7 +118,7 @@ public List> calculateDDay(Anniversary anniversary) { LocalDate hundredDays = anniversaryDate.plusDays(nextDay + i * 100); if (!hundredDays.isBefore(today)) { Map dDay = new HashMap<>(); - dDay.put((nextDay + i * 100) + "days", (int) ChronoUnit.DAYS.between(today, hundredDays)); + dDay.put((nextDay + i * 100) + "days", (int) ChronoUnit.DAYS.between(today, hundredDays)-1); dDayList.add(dDay); return dDayList; } From 3c632dfeb567f5faf147213873ab1854cc7b8203 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 22:02:07 +0900 Subject: [PATCH 4/9] =?UTF-8?q?fix:=20=EC=97=B0=EC=9D=B8=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=201=EB=85=84=EC=A3=BC=EA=B8=B0=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/anniversary/service/AnniversaryService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java index e7baa08..0ab1176 100644 --- a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java +++ b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java @@ -120,7 +120,7 @@ public List> calculateDDay(Anniversary anniversary) { Map dDay = new HashMap<>(); dDay.put((nextDay + i * 100) + "days", (int) ChronoUnit.DAYS.between(today, hundredDays)-1); dDayList.add(dDay); - return dDayList; + break; } } } @@ -132,7 +132,7 @@ public List> calculateDDay(Anniversary anniversary) { Map dDay = new HashMap<>(); dDay.put("year", (int) ChronoUnit.DAYS.between(today, yearAnniversary)); dDayList.add(dDay); - return dDayList; + break; } } From 511f32ae768b449b25b41cac4a7e7d6406aeafe7 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 22:22:41 +0900 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20=EC=97=B0=EC=9D=B8=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EB=B0=98=ED=99=98=201=EA=B0=9C=EB=A7=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/AnniversaryService.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java index 0ab1176..cd97df4 100644 --- a/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java +++ b/src/main/java/com/example/fiurinee/domain/anniversary/service/AnniversaryService.java @@ -108,34 +108,47 @@ public List> calculateDDay(Anniversary anniversary) { LocalDate today = LocalDate.now(); LocalDateTime anniversaryDateTime = anniversary.getAnniversaryDate().toLocalDateTime(); LocalDate anniversaryDate = anniversaryDateTime.toLocalDate(); - long yearsDifference = ChronoUnit.YEARS.between(anniversaryDate, today); + + Map closestDDay = null; + int minDays = Integer.MAX_VALUE; if (anniversary.getType() == AnniversaryType.연인) { int daysPassed = (int) ChronoUnit.DAYS.between(anniversaryDate, today); int nextDay = ((daysPassed / 100) + 1) * 100; - for (int i = 0; i < 1; i++) { + for (int i = 0; i < 1; i++) { // Only find the next closest 100-day anniversary LocalDate hundredDays = anniversaryDate.plusDays(nextDay + i * 100); if (!hundredDays.isBefore(today)) { - Map dDay = new HashMap<>(); - dDay.put((nextDay + i * 100) + "days", (int) ChronoUnit.DAYS.between(today, hundredDays)-1); - dDayList.add(dDay); + int daysToHundredDays = (int) ChronoUnit.DAYS.between(today, hundredDays) - 1; + if (daysToHundredDays < minDays) { + minDays = daysToHundredDays; + closestDDay = new HashMap<>(); + closestDDay.put((nextDay + i * 100) + "days", daysToHundredDays); + } break; } } } - + long yearsDifference = ChronoUnit.YEARS.between(anniversaryDate, today); for (int i = 1; i <= yearsDifference + 1; i++) { LocalDate yearAnniversary = anniversaryDate.plusYears(i); if (!yearAnniversary.isBefore(today)) { - Map dDay = new HashMap<>(); - dDay.put("year", (int) ChronoUnit.DAYS.between(today, yearAnniversary)); - dDayList.add(dDay); + int daysToYearAnniversary = (int) ChronoUnit.DAYS.between(today, yearAnniversary); + if (daysToYearAnniversary < minDays) { + minDays = daysToYearAnniversary; + closestDDay = new HashMap<>(); + closestDDay.put("year", daysToYearAnniversary); + } break; } } + if (closestDDay != null) { + dDayList.add(closestDDay); + } + + return dDayList; } From c6bbb663a10fa367c0d1c1d6c1c28ee6175b8008 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 22:51:41 +0900 Subject: [PATCH 6/9] =?UTF-8?q?chore:=20=EA=B8=B0=EB=85=90=EC=9D=BC=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/fiurinee/domain/member/dto/MemberResponseDTO.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java b/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java index ca47770..c9e4f26 100644 --- a/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java +++ b/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java @@ -5,6 +5,7 @@ import lombok.*; import java.net.URL; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -32,6 +33,8 @@ public static MemberResponseDTO of(Member member) { .profileImage(member.getProfileImage()) .alarm(member.isAlarm()) .anniversaries(member.getAnniversaries().stream() + .sorted(Comparator.comparingInt(anniversary -> + anniversaryService.calculateDDay(anniversary).get(0).values().iterator().next())) .map(anniversary -> Map.of( "id", anniversary.getId(), "name", anniversary.getName(), From 17fdedaf0649799698c061d293cb46e8fed02b98 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 22:58:38 +0900 Subject: [PATCH 7/9] =?UTF-8?q?chore:=20=EC=9D=B4=EC=A0=84=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/fiurinee/domain/member/dto/MemberResponseDTO.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java b/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java index c9e4f26..ca47770 100644 --- a/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java +++ b/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java @@ -5,7 +5,6 @@ import lombok.*; import java.net.URL; -import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -33,8 +32,6 @@ public static MemberResponseDTO of(Member member) { .profileImage(member.getProfileImage()) .alarm(member.isAlarm()) .anniversaries(member.getAnniversaries().stream() - .sorted(Comparator.comparingInt(anniversary -> - anniversaryService.calculateDDay(anniversary).get(0).values().iterator().next())) .map(anniversary -> Map.of( "id", anniversary.getId(), "name", anniversary.getName(), From 6cd9e64eaf730ea9897d22ee0d380ed970429a8f Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 23:12:52 +0900 Subject: [PATCH 8/9] =?UTF-8?q?chore:=20=EA=B8=B0=EB=85=90=EC=9D=BC=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/dto/MemberResponseDTO.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java b/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java index ca47770..8ae7a52 100644 --- a/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java +++ b/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java @@ -32,13 +32,21 @@ public static MemberResponseDTO of(Member member) { .profileImage(member.getProfileImage()) .alarm(member.isAlarm()) .anniversaries(member.getAnniversaries().stream() - .map(anniversary -> Map.of( - "id", anniversary.getId(), - "name", anniversary.getName(), - "anniversaryDate", anniversary.getAnniversaryDate().toString().substring(0,10), - "type", anniversary.getType().name(), - "dDays", anniversaryService.calculateDDay(anniversary) - )) + .map(anniversary -> { + List> dDays = anniversaryService.calculateDDay(anniversary); + return Map.of( + "id", anniversary.getId(), + "name", anniversary.getName(), + "anniversaryDate", anniversary.getAnniversaryDate().toString().substring(0, 10), + "type", anniversary.getType().name(), + "dDays", dDays + ); + }) + .sorted((a1, a2) -> { + Integer dDay1 = (Integer) ((Map.Entry) ((Map) a1.get("dDays").get(0)).entrySet().iterator().next()).getValue(); + Integer dDay2 = (Integer) ((Map.Entry) ((Map) a2.get("dDays").get(0)).entrySet().iterator().next()).getValue(); + return dDay1.compareTo(dDay2); + }) .collect(Collectors.toList())) .build(); } From c241c84b45fac49b5b63fa75787d9d6a77656857 Mon Sep 17 00:00:00 2001 From: jihyeon baek Date: Wed, 3 Jul 2024 23:30:42 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/fiurinee/domain/member/dto/MemberResponseDTO.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java b/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java index 8ae7a52..cacd8ce 100644 --- a/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java +++ b/src/main/java/com/example/fiurinee/domain/member/dto/MemberResponseDTO.java @@ -43,8 +43,8 @@ public static MemberResponseDTO of(Member member) { ); }) .sorted((a1, a2) -> { - Integer dDay1 = (Integer) ((Map.Entry) ((Map) a1.get("dDays").get(0)).entrySet().iterator().next()).getValue(); - Integer dDay2 = (Integer) ((Map.Entry) ((Map) a2.get("dDays").get(0)).entrySet().iterator().next()).getValue(); + Integer dDay1 = (Integer) ((Map) ((List) a1.get("dDays")).get(0)).values().iterator().next(); + Integer dDay2 = (Integer) ((Map) ((List) a2.get("dDays")).get(0)).values().iterator().next(); return dDay1.compareTo(dDay2); }) .collect(Collectors.toList()))