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