Skip to content

Commit 71c5655

Browse files
authored
Merge pull request #117 from GamSungPing/dev
예약 가능 조회에 휴무일 적용
2 parents 28a1766 + c853780 commit 71c5655

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/main/java/com/rocket/toucheese_be/domain/reservation/service/ReservationService.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.time.LocalTime;
2929
import java.util.Arrays;
3030
import java.util.List;
31+
import java.util.Map;
3132
import java.util.stream.Collectors;
3233

3334
@Slf4j
@@ -44,6 +45,16 @@ public class ReservationService {
4445
private final FcmService fcmService;
4546
private final DeviceService deviceService;
4647

48+
private static final Map<String, String> DAY_MAPPING = Map.of(
49+
"1", "일",
50+
"2", "월",
51+
"3", "화",
52+
"4", "수",
53+
"5", "목",
54+
"6", "금",
55+
"7", "토"
56+
);
57+
4758
// 스튜디오 예약 단일 조회
4859
public ReservationDto getReservationById(Long reservationId) {
4960
Reservation reservation = reservationRepository.findById(reservationId)
@@ -65,8 +76,19 @@ public AvailableTimeListDto getAvailableTimeSlots(Long studioId, LocalDate date)
6576
.filter(reservation -> reservation.getStatus() != ReservationStatus.cancel)
6677
.toList();
6778

79+
// 휴무일 정보
80+
String holidays = studio.getHolidays();
81+
if(holidays == null) holidays = "";
82+
else {
83+
holidays = holidays.replaceAll("&", "");
84+
holidays = holidays.chars()
85+
.mapToObj(c -> String.valueOf((char) c)) // 문자 하나씩 처리
86+
.map(c -> String.valueOf((Integer.parseInt(c) + 5) % 7 + 1)) // 변환 로직
87+
.collect(Collectors.joining());
88+
}
89+
6890
// 스튜디오의 예약 가능한 시간 계산
69-
List<LocalTime> availableSlots = studio.getAvailableTimeSlots(date, activeReservations);
91+
List<LocalTime> availableSlots = studio.getAvailableTimeSlots(date, activeReservations, holidays);
7092

7193
LocalTime lastSlot = availableSlots.isEmpty() ? null : availableSlots.get(availableSlots.size() - 1);
7294

src/main/java/com/rocket/toucheese_be/domain/studio/studio/entity/Studio.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@ private String calculatePriceCategoryBasedOnProfilePrice(int price) {
111111
}
112112

113113
// 예약 가능한 시간 조회 메서드
114-
public List<LocalTime> getAvailableTimeSlots(LocalDate date, List<Reservation> reservations) {
114+
public List<LocalTime> getAvailableTimeSlots(LocalDate date, List<Reservation> reservations, String holidays) {
115115
List<LocalTime> availableSlots = new ArrayList<>();
116116

117+
if (holidays.contains(date.getDayOfWeek().getValue()+"")) {
118+
return availableSlots; // 휴무일이면 빈 리스트 반환
119+
}
120+
117121
if (reservations == null) {
118122
reservations = new ArrayList<>();
119123
}

0 commit comments

Comments
 (0)