Skip to content

Commit

Permalink
#90 [feat] : 유저는 마이페이지에서 고정 스케줄을 상세 조회할 수 있다
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Oct 23, 2024
1 parent 45b4e57 commit 5656573
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/main/java/side/onetime/controller/FixedController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,4 +41,15 @@ public ResponseEntity<ApiResponse<List<FixedEventResponse>>> getAllFixedSchedule

return ApiResponse.onSuccess(SuccessStatus._GET_ALL_FIXED_SCHEDULES, fixedEventResponses);
}

// 특정 고정 스케줄 상세 조회 API
@GetMapping("/{id}")
public ResponseEntity<ApiResponse<FixedEventDetailResponse>> getFixedScheduleDetail(
@RequestHeader("Authorization") String authorizationHeader,
@PathVariable("id") Long fixedScheduleId) {

FixedEventDetailResponse fixedEventDetailResponse = fixedScheduleService.getFixedScheduleDetail(authorizationHeader, fixedScheduleId);

return ApiResponse.onSuccess(SuccessStatus._GET_FIXED_SCHEDULE_DETAIL, fixedEventDetailResponse);
}
}
Original file line number Diff line number Diff line change
@@ -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<FixedScheduleResponse> schedules
) {
public static FixedEventDetailResponse of(String title, String startTime, String endTime, List<FixedScheduleResponse> schedules) {
return new FixedEventDetailResponse(
title,
startTime,
endTime,
schedules
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record FixedEventResponse(
String endTime,
List<FixedScheduleResponse> schedules
) {
public static FixedEventResponse of (Long id, String startTime, String endTime, List<FixedScheduleResponse> schedules) {
public static FixedEventResponse of(Long id, String startTime, String endTime, List<FixedScheduleResponse> schedules) {
return new FixedEventResponse(
id,
startTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/side/onetime/service/FixedScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,7 +60,6 @@ public void createFixedSchedules(CreateFixedEventRequest createFixedEventRequest
public List<FixedEventResponse> getAllFixedSchedules(String authorizationHeader) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);

// 유저의 고정 이벤트와 해당 이벤트에 대한 고정 선택 및 고정 스케줄을 QueryDSL로 조회
List<FixedEvent> fixedEvents = fixedEventRepository.findAllByUser(user);

if (fixedEvents.isEmpty()) {
Expand Down Expand Up @@ -87,4 +87,31 @@ public List<FixedEventResponse> 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<String, List<String>> groupedSchedules = fixedEvent.getFixedSelections().stream()
.collect(Collectors.groupingBy(
selection -> selection.getFixedSchedule().getDay(),
Collectors.mapping(selection -> selection.getFixedSchedule().getTime(), Collectors.toList())
));

// 고정 스케줄 정보 생성
List<FixedScheduleResponse> 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);
}
}

0 comments on commit 5656573

Please sign in to comment.