-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
238 additions
and
17 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/org/sopt/app/application/calendar/CalendarService.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,8 @@ | ||
package org.sopt.app.application.calendar; | ||
|
||
import java.util.List; | ||
import org.sopt.app.presentation.calendar.CalendarResponse; | ||
|
||
public interface CalendarService { | ||
List<CalendarResponse> getAllCurrentGenerationCalendar(); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/org/sopt/app/application/calendar/CalendarServiceImpl.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,45 @@ | ||
package org.sopt.app.application.calendar; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.app.domain.cache.CachedAllCalendarResponse; | ||
import org.sopt.app.domain.cache.Calendars; | ||
import org.sopt.app.interfaces.postgres.CalendarRepository; | ||
import org.sopt.app.interfaces.postgres.redis.CachedCalendarRepository; | ||
import org.sopt.app.presentation.calendar.CalendarResponse; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CalendarServiceImpl implements CalendarService { | ||
|
||
private final CalendarRepository calendarRepository; | ||
private final CachedCalendarRepository cachedCalendarRepository; | ||
|
||
@Value("${sopt.current.generation}") | ||
private Integer currentGeneration; | ||
|
||
@Override | ||
@Transactional | ||
public List<CalendarResponse> getAllCurrentGenerationCalendar() { | ||
|
||
Optional<CachedAllCalendarResponse> cachedCalendar = cachedCalendarRepository.findById(currentGeneration); | ||
|
||
return cachedCalendar.orElseGet(this::cacheAllCalendarResponse) | ||
.getCalendars().calendars().stream() | ||
.map(CalendarResponse::of) | ||
.toList(); | ||
} | ||
|
||
private CachedAllCalendarResponse cacheAllCalendarResponse() { | ||
return cachedCalendarRepository.save( | ||
new CachedAllCalendarResponse( | ||
currentGeneration, | ||
new Calendars(calendarRepository.findAllByGenerationOrderByStartDate(currentGeneration)) | ||
) | ||
); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/org/sopt/app/domain/cache/CachedAllCalendarResponse.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,17 @@ | ||
package org.sopt.app.domain.cache; | ||
|
||
import lombok.*; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PUBLIC) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@RedisHash(value = "allCalendar", timeToLive = 60 * 60 * 24 * 7L) | ||
public class CachedAllCalendarResponse { | ||
|
||
@Id | ||
private Integer generation; | ||
|
||
private Calendars calendars; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.sopt.app.domain.cache; | ||
|
||
import java.util.List; | ||
import org.sopt.app.domain.entity.Calendar; | ||
|
||
public record Calendars( | ||
List<Calendar> calendars | ||
) { } |
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,41 @@ | ||
package org.sopt.app.domain.entity; | ||
|
||
import lombok.*; | ||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDate; | ||
import org.sopt.app.domain.enums.CalendarType; | ||
|
||
@Getter | ||
@Entity | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Calendar { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotNull | ||
private Integer generation; | ||
|
||
@NotNull | ||
private String title; | ||
|
||
@NotNull | ||
private Boolean isOneDaySchedule; | ||
|
||
@NotNull | ||
private Boolean isOnlyActiveGeneration; | ||
|
||
@NotNull | ||
private LocalDate startDate; | ||
|
||
@NotNull | ||
private LocalDate endDate; | ||
|
||
@NotNull | ||
@Enumerated(EnumType.STRING) | ||
private CalendarType type; | ||
} |
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,5 @@ | ||
package org.sopt.app.domain.enums; | ||
|
||
public enum CalendarType { | ||
EVENT, SEMINAR | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/sopt/app/interfaces/postgres/CalendarRepository.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,10 @@ | ||
package org.sopt.app.interfaces.postgres; | ||
|
||
import java.util.List; | ||
import org.sopt.app.domain.entity.Calendar; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CalendarRepository extends JpaRepository<Calendar, Long> { | ||
|
||
List<Calendar> findAllByGenerationOrderByStartDate(final Integer generation); | ||
} |
7 changes: 0 additions & 7 deletions
7
src/main/java/org/sopt/app/interfaces/postgres/RecommendedUserIdsRepository.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/main/java/org/sopt/app/interfaces/postgres/redis/CachedCalendarRepository.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,8 @@ | ||
package org.sopt.app.interfaces.postgres.redis; | ||
|
||
import org.sopt.app.domain.cache.CachedAllCalendarResponse; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface CachedCalendarRepository extends CrudRepository<CachedAllCalendarResponse, Integer> { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/sopt/app/interfaces/postgres/redis/CachedRecommendedUserIdsRepository.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,7 @@ | ||
package org.sopt.app.interfaces.postgres.redis; | ||
|
||
import org.sopt.app.domain.cache.CachedRecommendedUserIds; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface CachedRecommendedUserIdsRepository extends CrudRepository<CachedRecommendedUserIds, String> { | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/sopt/app/presentation/calendar/CalendarController.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,31 @@ | ||
package org.sopt.app.presentation.calendar; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.app.application.calendar.CalendarService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v2/calendar") | ||
public class CalendarController { | ||
|
||
private final CalendarService calendarService; | ||
|
||
@Operation(summary = "일정 전체 보기") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "success"), | ||
@ApiResponse(responseCode = "500", description = "server error", content = @Content) | ||
}) | ||
@GetMapping("/all") | ||
public ResponseEntity<List<CalendarResponse>> getAllCalendar() { | ||
return ResponseEntity.ok( | ||
calendarService.getAllCurrentGenerationCalendar() | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/sopt/app/presentation/calendar/CalendarResponse.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,26 @@ | ||
package org.sopt.app.presentation.calendar; | ||
|
||
import java.time.LocalDate; | ||
import lombok.*; | ||
import org.sopt.app.domain.entity.Calendar; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class CalendarResponse { | ||
private final String title; | ||
private final LocalDate startDate; | ||
private final LocalDate endDate; | ||
private final Boolean isOneDaySchedule; | ||
private final Boolean isOnlyActiveGeneration; | ||
|
||
public static CalendarResponse of(Calendar calendar) { | ||
return CalendarResponse.builder() | ||
.startDate(calendar.getStartDate()) | ||
.endDate(calendar.getEndDate()) | ||
.title(calendar.getTitle()) | ||
.isOneDaySchedule(calendar.getIsOneDaySchedule()) | ||
.isOnlyActiveGeneration(calendar.getIsOnlyActiveGeneration()) | ||
.build(); | ||
} | ||
} |