From c7735898fc3a783e937916f21d455d66d8c2b694 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 11 Nov 2024 01:23:51 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[feat]=20=EC=B5=9C=EA=B7=BC=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EB=B3=B4=EA=B8=B0=20controller=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#429)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/application/calendar/CalendarService.java | 4 +++- .../presentation/calendar/CalendarController.java | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sopt/app/application/calendar/CalendarService.java b/src/main/java/org/sopt/app/application/calendar/CalendarService.java index a5072d06..c9579658 100644 --- a/src/main/java/org/sopt/app/application/calendar/CalendarService.java +++ b/src/main/java/org/sopt/app/application/calendar/CalendarService.java @@ -2,7 +2,9 @@ import java.util.List; import org.sopt.app.presentation.calendar.CalendarResponse; +import org.sopt.app.presentation.calendar.RecentCalendarResponse; public interface CalendarService { - List getAllCurrentGenerationCalendar(); + List getAllCurrentGenerationCalendarResponse(); + RecentCalendarResponse getRecentCalendarResponse(); } diff --git a/src/main/java/org/sopt/app/presentation/calendar/CalendarController.java b/src/main/java/org/sopt/app/presentation/calendar/CalendarController.java index 70ea29f7..4f7442e3 100644 --- a/src/main/java/org/sopt/app/presentation/calendar/CalendarController.java +++ b/src/main/java/org/sopt/app/presentation/calendar/CalendarController.java @@ -25,7 +25,19 @@ public class CalendarController { @GetMapping("/all") public ResponseEntity> getAllCalendar() { return ResponseEntity.ok( - calendarService.getAllCurrentGenerationCalendar() + calendarService.getAllCurrentGenerationCalendarResponse() + ); + } + + @Operation(summary = "최근 일정 보기") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "success"), + @ApiResponse(responseCode = "500", description = "server error", content = @Content) + }) + @GetMapping("/recent") + public ResponseEntity getRecentCalendar() { + return ResponseEntity.ok( + calendarService.getRecentCalendarResponse() ); } } From 3e64a1e38084e8ad46dd7f72b961162acbe72ced Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 11 Nov 2024 01:24:07 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[feat]=20=EC=B5=9C=EA=B7=BC=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EB=B3=B4=EA=B8=B0=20DTO=20=EC=B6=94=EA=B0=80=20(#4?= =?UTF-8?q?29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/RecentCalendarResponse.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/org/sopt/app/presentation/calendar/RecentCalendarResponse.java diff --git a/src/main/java/org/sopt/app/presentation/calendar/RecentCalendarResponse.java b/src/main/java/org/sopt/app/presentation/calendar/RecentCalendarResponse.java new file mode 100644 index 00000000..eb2f30d2 --- /dev/null +++ b/src/main/java/org/sopt/app/presentation/calendar/RecentCalendarResponse.java @@ -0,0 +1,36 @@ +package org.sopt.app.presentation.calendar; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import lombok.Getter; +import org.sopt.app.domain.entity.Calendar; +import org.sopt.app.domain.enums.CalendarType; + +@Getter +public class RecentCalendarResponse{ + private final String date; + private final CalendarType type; + private final String title; + + public static RecentCalendarResponse of(Calendar calendar){ + return new RecentCalendarResponse( + calendar.getStartDate(), + calendar.getType(), + calendar.getTitle() + ); + } + + public static RecentCalendarResponse createEmptyCalendar(LocalDate date){ + return new RecentCalendarResponse( + date, + CalendarType.ETC, + "일정이 없습니다." + ); + } + + private RecentCalendarResponse(final LocalDate date, final CalendarType type, final String title){ + this.date = date.format(DateTimeFormatter.ofPattern("MM-dd")); + this.type = type; + this.title = title; + } +} From 43cc6ded4dc64acc1c78365b03446c56b6995368 Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 11 Nov 2024 01:24:28 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[feat]=20=EC=B5=9C=EA=B7=BC=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EB=B3=B4=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#429)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/CalendarServiceImpl.java | 50 ++++++++++++------- .../sopt/app/domain/enums/CalendarType.java | 2 +- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.java b/src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.java index e10c1467..bf96d908 100644 --- a/src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.java +++ b/src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.java @@ -1,13 +1,14 @@ package org.sopt.app.application.calendar; -import java.util.List; -import java.util.Optional; +import java.time.*; +import java.util.*; import lombok.RequiredArgsConstructor; -import org.sopt.app.domain.cache.CachedAllCalendarResponse; -import org.sopt.app.domain.cache.Calendars; +import org.sopt.app.domain.cache.*; +import org.sopt.app.domain.entity.Calendar; import org.sopt.app.interfaces.postgres.CalendarRepository; import org.sopt.app.interfaces.postgres.redis.CachedCalendarRepository; import org.sopt.app.presentation.calendar.CalendarResponse; +import org.sopt.app.presentation.calendar.RecentCalendarResponse; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,22 +25,37 @@ public class CalendarServiceImpl implements CalendarService { @Override @Transactional - public List getAllCurrentGenerationCalendar() { + public List getAllCurrentGenerationCalendarResponse() { - Optional cachedCalendar = cachedCalendarRepository.findById(currentGeneration); - - return cachedCalendar.orElseGet(this::cacheAllCalendarResponse) - .getCalendars().calendars().stream() + return this.getAllCurrentGenerationCalendar().stream() .map(CalendarResponse::of) .toList(); } - private CachedAllCalendarResponse cacheAllCalendarResponse() { - return cachedCalendarRepository.save( - new CachedAllCalendarResponse( - currentGeneration, - new Calendars(calendarRepository.findAllByGenerationOrderByStartDate(currentGeneration)) - ) - ); + private List getAllCurrentGenerationCalendar() { + Optional cachedCalendar = cachedCalendarRepository.findById(currentGeneration); + + if (cachedCalendar.isPresent()) { + return cachedCalendar.get().getCalendars().calendars(); + } + + return this.cacheAllCalendarResponse(); + } + + private List cacheAllCalendarResponse() { + List calendars = calendarRepository.findAllByGenerationOrderByStartDate(currentGeneration); + cachedCalendarRepository.save(new CachedAllCalendarResponse(currentGeneration, new Calendars(calendars))); + return calendars; + } + + @Override + @Transactional + public RecentCalendarResponse getRecentCalendarResponse() { + LocalDate now = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDate(); + + return this.getAllCurrentGenerationCalendar().stream() + .filter(calendar -> calendar.getEndDate().isAfter(now)) + .findFirst().map(RecentCalendarResponse::of) + .orElseGet(() -> RecentCalendarResponse.createEmptyCalendar(now)); } -} +} \ No newline at end of file diff --git a/src/main/java/org/sopt/app/domain/enums/CalendarType.java b/src/main/java/org/sopt/app/domain/enums/CalendarType.java index aaee73a8..a259e62e 100644 --- a/src/main/java/org/sopt/app/domain/enums/CalendarType.java +++ b/src/main/java/org/sopt/app/domain/enums/CalendarType.java @@ -1,5 +1,5 @@ package org.sopt.app.domain.enums; public enum CalendarType { - EVENT, SEMINAR + EVENT, SEMINAR, ETC } From 6b8c08bd7b4b5bf7cb5dcae32aa32605ac7da0ca Mon Sep 17 00:00:00 2001 From: kseysh Date: Mon, 11 Nov 2024 01:27:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[feat]=20=EC=B5=9C=EA=B7=BC=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EB=B3=B4=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=98=84=EC=9E=AC=20=EB=82=A0=EC=A7=9C=EB=A5=BC=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=ED=95=98=EC=97=AC=20=EA=B0=80=EC=9E=A5=20?= =?UTF-8?q?=EC=B5=9C=EA=B7=BC=EC=9D=98=20=EC=9D=BC=EC=A0=95=EC=9D=84=20?= =?UTF-8?q?=EB=B3=B4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#429)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/app/application/calendar/CalendarServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.java b/src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.java index bf96d908..5bf93ca1 100644 --- a/src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.java +++ b/src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.java @@ -54,7 +54,7 @@ public RecentCalendarResponse getRecentCalendarResponse() { LocalDate now = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDate(); return this.getAllCurrentGenerationCalendar().stream() - .filter(calendar -> calendar.getEndDate().isAfter(now)) + .filter(calendar -> !calendar.getStartDate().isBefore(now)) .findFirst().map(RecentCalendarResponse::of) .orElseGet(() -> RecentCalendarResponse.createEmptyCalendar(now)); }