From fa796c8b7c0fbb47d39009ed27f6c099dbaf56eb Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Wed, 30 Oct 2024 02:53:30 +0900 Subject: [PATCH] =?UTF-8?q?#91=20[feat]=20:=20=EC=9C=A0=EC=A0=80=EB=8A=94?= =?UTF-8?q?=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EA=B3=A0=EC=A0=95=20=EC=8A=A4=EC=BC=80=EC=A4=84?= =?UTF-8?q?=EC=9D=84=20=EC=9A=94=EC=9D=BC=EB=B3=84=EB=A1=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onetime/controller/FixedController.java | 12 +++++++ .../response/FixedEventByDayResponse.java | 23 +++++++++++++ .../exception/status/FixedErrorStatus.java | 1 + .../global/common/status/SuccessStatus.java | 1 + .../onetime/service/FixedEventService.java | 33 +++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 src/main/java/side/onetime/dto/fixed/response/FixedEventByDayResponse.java diff --git a/src/main/java/side/onetime/controller/FixedController.java b/src/main/java/side/onetime/controller/FixedController.java index 080b6fa..d71f368 100644 --- a/src/main/java/side/onetime/controller/FixedController.java +++ b/src/main/java/side/onetime/controller/FixedController.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.*; import side.onetime.dto.fixed.request.CreateFixedEventRequest; import side.onetime.dto.fixed.request.ModifyFixedEventRequest; +import side.onetime.dto.fixed.response.FixedEventByDayResponse; import side.onetime.dto.fixed.response.FixedEventDetailResponse; import side.onetime.dto.fixed.response.FixedEventResponse; import side.onetime.global.common.ApiResponse; @@ -81,4 +82,15 @@ public ResponseEntity> removeFixedEvent( return ApiResponse.onSuccess(SuccessStatus._REMOVE_FIXED_SCHEDULE); } + + // 요일별 고정 이벤트 조회 API + @GetMapping("by-day/{day}") + public ResponseEntity>> getFixedEventByDay( + @RequestHeader("Authorization") String authorizationHeader, + @PathVariable("day") String day) { + + List response = fixedEventService.getFixedEventByDay(authorizationHeader, day); + + return ApiResponse.onSuccess(SuccessStatus._GET_FIXED_EVENT_BY_DAY, response); + } } diff --git a/src/main/java/side/onetime/dto/fixed/response/FixedEventByDayResponse.java b/src/main/java/side/onetime/dto/fixed/response/FixedEventByDayResponse.java new file mode 100644 index 0000000..ed86742 --- /dev/null +++ b/src/main/java/side/onetime/dto/fixed/response/FixedEventByDayResponse.java @@ -0,0 +1,23 @@ +package side.onetime.dto.fixed.response; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record FixedEventByDayResponse( + Long id, + String title, + String startTime, + String endTime +) { + public static FixedEventByDayResponse of(Long id, String title, String startTime, String endTime) { + return new FixedEventByDayResponse( + id, + title, + startTime, + endTime + ); + } +} \ No newline at end of file diff --git a/src/main/java/side/onetime/exception/status/FixedErrorStatus.java b/src/main/java/side/onetime/exception/status/FixedErrorStatus.java index fccbac7..8e767e9 100644 --- a/src/main/java/side/onetime/exception/status/FixedErrorStatus.java +++ b/src/main/java/side/onetime/exception/status/FixedErrorStatus.java @@ -13,6 +13,7 @@ public enum FixedErrorStatus implements BaseErrorCode { _NOT_FOUND_FIXED_EVENTS(HttpStatus.NOT_FOUND, "FIXED-002", "고정 이벤트 목록을 가져오는 데 실패했습니다."), _NOT_FOUND_FIXED_EVENT(HttpStatus.NOT_FOUND, "FIXED-003", "특정 고정 이벤트를 가져오는 데 실패했습니다."), _NOT_FOUND_FIXED_SELECTIONS(HttpStatus.NOT_FOUND, "FIXED-004", "고정 스케줄 선택 목록을 가져오는 데 실패했습니다."), + _IS_NOT_RIGHT_DAY(HttpStatus.BAD_REQUEST, "FIXED-005", "올바른 요일 형식이 아닙니다."), ; private final HttpStatus httpStatus; diff --git a/src/main/java/side/onetime/global/common/status/SuccessStatus.java b/src/main/java/side/onetime/global/common/status/SuccessStatus.java index 943f144..9fefd12 100644 --- a/src/main/java/side/onetime/global/common/status/SuccessStatus.java +++ b/src/main/java/side/onetime/global/common/status/SuccessStatus.java @@ -50,6 +50,7 @@ public enum SuccessStatus implements BaseCode { _GET_FIXED_SCHEDULE_DETAIL(HttpStatus.OK, "200", "특정 고정 스케줄 상세 조회에 성공했습니다."), _MODIFY_FIXED_SCHEDULE(HttpStatus.OK, "200", "고정 스케줄 수정에 성공했습니다."), _REMOVE_FIXED_SCHEDULE(HttpStatus.OK, "200", "고정 스케줄 삭제에 성공했습니다."), + _GET_FIXED_EVENT_BY_DAY(HttpStatus.OK, "200", "요일 별 고정 스케줄 조회에 성공했습니다."), ; private final HttpStatus httpStatus; diff --git a/src/main/java/side/onetime/service/FixedEventService.java b/src/main/java/side/onetime/service/FixedEventService.java index 239e070..c9c1280 100644 --- a/src/main/java/side/onetime/service/FixedEventService.java +++ b/src/main/java/side/onetime/service/FixedEventService.java @@ -7,6 +7,7 @@ import side.onetime.domain.User; import side.onetime.dto.fixed.request.CreateFixedEventRequest; import side.onetime.dto.fixed.request.ModifyFixedEventRequest; +import side.onetime.dto.fixed.response.FixedEventByDayResponse; import side.onetime.exception.CustomException; import side.onetime.exception.status.FixedErrorStatus; import side.onetime.repository.FixedEventRepository; @@ -52,4 +53,36 @@ public void removeFixedEvent(String authorizationHeader, Long fixedEventId) { .orElseThrow(() -> new CustomException(FixedErrorStatus._NOT_FOUND_FIXED_EVENT)); fixedEventRepository.deleteFixedEventAndSelections(user, fixedEventId); } + + // 요일 별 고정 이벤트 조회 메서드 + @Transactional(readOnly = true) + public List getFixedEventByDay(String authorizationHeader, String day) { + User user = jwtUtil.getUserFromHeader(authorizationHeader); + String koreanDay = convertDayToKorean(day); + + List fixedEvents = fixedEventRepository.findFixedEventsByUserAndDay(user, koreanDay); + + return fixedEvents.stream() + .map(fixedEvent -> FixedEventByDayResponse.of( + fixedEvent.getId(), + fixedEvent.getTitle(), + fixedEvent.getStartTime(), + fixedEvent.getEndTime() + )) + .toList(); + } + + // 영어 요일 -> 한글 요일 변환 메서드 + private String convertDayToKorean(String day) { + return switch (day.toLowerCase()) { + case "mon" -> "월"; + case "tue" -> "화"; + case "wed" -> "수"; + case "thu" -> "목"; + case "fri" -> "금"; + case "sat" -> "토"; + case "sun" -> "일"; + default -> throw new CustomException(FixedErrorStatus._IS_NOT_RIGHT_DAY); + }; + } } \ No newline at end of file