diff --git a/src/main/java/side/onetime/controller/FixedController.java b/src/main/java/side/onetime/controller/FixedController.java index 4d5b9ee..accf958 100644 --- a/src/main/java/side/onetime/controller/FixedController.java +++ b/src/main/java/side/onetime/controller/FixedController.java @@ -5,6 +5,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import side.onetime.dto.fixed.request.CreateFixedEventRequest; +import side.onetime.dto.fixed.response.FixedEventDetailResponse; import side.onetime.dto.fixed.response.FixedEventResponse; import side.onetime.global.common.ApiResponse; import side.onetime.global.common.status.SuccessStatus; @@ -40,4 +41,15 @@ public ResponseEntity>> getAllFixedSchedule return ApiResponse.onSuccess(SuccessStatus._GET_ALL_FIXED_SCHEDULES, fixedEventResponses); } + + // 특정 고정 스케줄 상세 조회 API + @GetMapping("/{id}") + public ResponseEntity> getFixedScheduleDetail( + @RequestHeader("Authorization") String authorizationHeader, + @PathVariable("id") Long fixedScheduleId) { + + FixedEventDetailResponse fixedEventDetailResponse = fixedScheduleService.getFixedScheduleDetail(authorizationHeader, fixedScheduleId); + + return ApiResponse.onSuccess(SuccessStatus._GET_FIXED_SCHEDULE_DETAIL, fixedEventDetailResponse); + } } diff --git a/src/main/java/side/onetime/dto/fixed/response/FixedEventDetailResponse.java b/src/main/java/side/onetime/dto/fixed/response/FixedEventDetailResponse.java new file mode 100644 index 0000000..b7e779b --- /dev/null +++ b/src/main/java/side/onetime/dto/fixed/response/FixedEventDetailResponse.java @@ -0,0 +1,25 @@ +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; + +import java.util.List; + +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record FixedEventDetailResponse( + String title, + String startTime, + String endTime, + List schedules +) { + public static FixedEventDetailResponse of(String title, String startTime, String endTime, List schedules) { + return new FixedEventDetailResponse( + title, + startTime, + endTime, + schedules + ); + } +} \ No newline at end of file diff --git a/src/main/java/side/onetime/dto/fixed/response/FixedEventResponse.java b/src/main/java/side/onetime/dto/fixed/response/FixedEventResponse.java index 1fad285..10c84de 100644 --- a/src/main/java/side/onetime/dto/fixed/response/FixedEventResponse.java +++ b/src/main/java/side/onetime/dto/fixed/response/FixedEventResponse.java @@ -14,7 +14,7 @@ public record FixedEventResponse( String endTime, List schedules ) { - public static FixedEventResponse of (Long id, String startTime, String endTime, List schedules) { + public static FixedEventResponse of(Long id, String startTime, String endTime, List schedules) { return new FixedEventResponse( id, startTime, diff --git a/src/main/java/side/onetime/exception/status/FixedErrorStatus.java b/src/main/java/side/onetime/exception/status/FixedErrorStatus.java index 75a462e..fccbac7 100644 --- a/src/main/java/side/onetime/exception/status/FixedErrorStatus.java +++ b/src/main/java/side/onetime/exception/status/FixedErrorStatus.java @@ -11,7 +11,8 @@ public enum FixedErrorStatus implements BaseErrorCode { _NOT_FOUND_FIXED_SCHEDULES(HttpStatus.NOT_FOUND, "FIXED-001", "고정 스케줄 목록을 가져오는 데 실패했습니다."), _NOT_FOUND_FIXED_EVENTS(HttpStatus.NOT_FOUND, "FIXED-002", "고정 이벤트 목록을 가져오는 데 실패했습니다."), - _NOT_FOUND_FIXED_SELECTIONS(HttpStatus.NOT_FOUND, "FIXED-003", "고정 스케줄 선택 목록을 가져오는 데 실패했습니다."), + _NOT_FOUND_FIXED_EVENT(HttpStatus.NOT_FOUND, "FIXED-003", "특정 고정 이벤트를 가져오는 데 실패했습니다."), + _NOT_FOUND_FIXED_SELECTIONS(HttpStatus.NOT_FOUND, "FIXED-004", "고정 스케줄 선택 목록을 가져오는 데 실패했습니다."), ; 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 c58a45a..12c67f2 100644 --- a/src/main/java/side/onetime/global/common/status/SuccessStatus.java +++ b/src/main/java/side/onetime/global/common/status/SuccessStatus.java @@ -47,6 +47,7 @@ public enum SuccessStatus implements BaseCode { // Fixed _CREATED_FIXED_SCHEDULE(HttpStatus.CREATED, "201", "고정 스케줄 등록에 성공했습니다."), _GET_ALL_FIXED_SCHEDULES(HttpStatus.OK, "200", "전체 고정 스케줄 조회에 성공했습니다."), + _GET_FIXED_SCHEDULE_DETAIL(HttpStatus.OK, "200", "특정 고정 스케줄 상세 조회에 성공했습니다."), ; private final HttpStatus httpStatus; diff --git a/src/main/java/side/onetime/service/FixedScheduleService.java b/src/main/java/side/onetime/service/FixedScheduleService.java index a5384f5..dec1f2e 100644 --- a/src/main/java/side/onetime/service/FixedScheduleService.java +++ b/src/main/java/side/onetime/service/FixedScheduleService.java @@ -8,6 +8,7 @@ import side.onetime.domain.FixedSelection; import side.onetime.domain.User; import side.onetime.dto.fixed.request.CreateFixedEventRequest; +import side.onetime.dto.fixed.response.FixedEventDetailResponse; import side.onetime.dto.fixed.response.FixedEventResponse; import side.onetime.dto.fixed.response.FixedScheduleResponse; import side.onetime.exception.CustomException; @@ -59,7 +60,6 @@ public void createFixedSchedules(CreateFixedEventRequest createFixedEventRequest public List getAllFixedSchedules(String authorizationHeader) { User user = jwtUtil.getUserFromHeader(authorizationHeader); - // 유저의 고정 이벤트와 해당 이벤트에 대한 고정 선택 및 고정 스케줄을 QueryDSL로 조회 List fixedEvents = fixedEventRepository.findAllByUser(user); if (fixedEvents.isEmpty()) { @@ -87,4 +87,31 @@ public List getAllFixedSchedules(String authorizationHeader) return fixedEventResponses; } + + // 특정 고정 스케줄 상세 조회 메서드 + @Transactional(readOnly = true) + public FixedEventDetailResponse getFixedScheduleDetail(String authorizationHeader, Long fixedScheduleId) { + User user = jwtUtil.getUserFromHeader(authorizationHeader); + + // 고정 이벤트 조회 + FixedEvent fixedEvent = fixedEventRepository.findByUserAndFixedEventId(user, fixedScheduleId); + if (fixedEvent == null) { + throw new CustomException(FixedErrorStatus._NOT_FOUND_FIXED_EVENT); + } + + // 고정 선택을 요일별로 그룹화하여 시간 목록을 생성 + Map> groupedSchedules = fixedEvent.getFixedSelections().stream() + .collect(Collectors.groupingBy( + selection -> selection.getFixedSchedule().getDay(), + Collectors.mapping(selection -> selection.getFixedSchedule().getTime(), Collectors.toList()) + )); + + // 고정 스케줄 정보 생성 + List scheduleResponses = groupedSchedules.entrySet().stream() + .map(entry -> FixedScheduleResponse.of(entry.getKey(), entry.getValue())) + .collect(Collectors.toList()); + + // 고정 이벤트 상세 정보 반환 + return FixedEventDetailResponse.of(fixedEvent.getTitle(), fixedEvent.getStartTime(), fixedEvent.getEndTime(), scheduleResponses); + } } \ No newline at end of file