From 56565737b4a8de560b0e3c467362fe6cf8151319 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Wed, 23 Oct 2024 21:19:05 +0900 Subject: [PATCH] =?UTF-8?q?#90=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=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=ED=95=A0=20?= =?UTF-8?q?=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/FixedEventDetailResponse.java | 25 ++++++++++++++++ .../fixed/response/FixedEventResponse.java | 2 +- .../exception/status/FixedErrorStatus.java | 3 +- .../global/common/status/SuccessStatus.java | 1 + .../onetime/service/FixedScheduleService.java | 29 ++++++++++++++++++- 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/main/java/side/onetime/dto/fixed/response/FixedEventDetailResponse.java 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