diff --git a/src/main/java/B1G4/bookmark/apiPayload/code/status/ErrorStatus.java b/src/main/java/B1G4/bookmark/apiPayload/code/status/ErrorStatus.java index 00dfd58..29ba1fa 100644 --- a/src/main/java/B1G4/bookmark/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/B1G4/bookmark/apiPayload/code/status/ErrorStatus.java @@ -56,6 +56,7 @@ public enum ErrorStatus implements BaseErrorCode { UNBOOKMARK_FAILED(HttpStatus.BAD_REQUEST, "PLACE_010", "해당 공간 북마크 해제에 실패하였습니다."), USERPLACE_NOT_FOUND(HttpStatus.BAD_REQUEST, "PLACE_011", "해당 유저의 저장 공간이 존재하지 않습니다."), PLACE_NOT_FOUND(HttpStatus.BAD_REQUEST, "PLACE_012", "해당 공간이 존재하지 않습니다."), + PLACE_CLOSED(HttpStatus.BAD_REQUEST, "PLACE_013", "해당 공간은 오늘 휴무일입니다."), ; diff --git a/src/main/java/B1G4/bookmark/converter/CongestionConverter.java b/src/main/java/B1G4/bookmark/converter/CongestionConverter.java index 3c3ce26..5abdf7c 100644 --- a/src/main/java/B1G4/bookmark/converter/CongestionConverter.java +++ b/src/main/java/B1G4/bookmark/converter/CongestionConverter.java @@ -1,5 +1,7 @@ package B1G4.bookmark.converter; +import B1G4.bookmark.apiPayload.code.status.ErrorStatus; +import B1G4.bookmark.apiPayload.exception.handler.PlaceHandler; import B1G4.bookmark.domain.Congestion; import B1G4.bookmark.domain.Place; import B1G4.bookmark.web.dto.CongestionDTO.CongestionResponseDTO; @@ -102,6 +104,12 @@ private static Congestion.CongestionBuilder setCongestionLevel(Congestion.Conges public static List filterAndRoundCongestion(Congestion congestion, LocalTime openTime, LocalTime closeTime) { List congestionData = new ArrayList<>(); + try{ + int hour = openTime.getHour(); + }catch (Exception e){ + throw new PlaceHandler(ErrorStatus.PLACE_CLOSED); + } + for (int hour = openTime.getHour(); hour <= closeTime.getHour(); hour++) { float congestionLevel = getCongestionLevel(congestion, hour); int roundedValue = Math.round(congestionLevel); diff --git a/src/main/java/B1G4/bookmark/service/CongestionService/CongestionServiceImpl.java b/src/main/java/B1G4/bookmark/service/CongestionService/CongestionServiceImpl.java index fe18501..2125af5 100644 --- a/src/main/java/B1G4/bookmark/service/CongestionService/CongestionServiceImpl.java +++ b/src/main/java/B1G4/bookmark/service/CongestionService/CongestionServiceImpl.java @@ -1,5 +1,7 @@ package B1G4.bookmark.service.CongestionService; +import B1G4.bookmark.apiPayload.code.status.ErrorStatus; +import B1G4.bookmark.apiPayload.exception.handler.PlaceHandler; import B1G4.bookmark.converter.CongestionConverter; import B1G4.bookmark.domain.Congestion; import B1G4.bookmark.domain.OperatingTime; @@ -38,8 +40,14 @@ public CongestionResponseDTO getCongestionGraph(Long placeId) { OperatingTime operatingTime = operatingTimeRepository.findByPlaceAndDayOfWeek(place, currentDay); - LocalTime openTime = operatingTime.getOpenTime(); - LocalTime closeTime = operatingTime.getCloseTime(); + LocalTime openTime; + LocalTime closeTime; + try { + openTime = operatingTime.getOpenTime(); + closeTime = operatingTime.getCloseTime(); + }catch (Exception e){ + throw new PlaceHandler(ErrorStatus.PLACE_CLOSED); + } Congestion congestion = place.getCongestion(); if (congestion == null) {