Skip to content

Commit

Permalink
#91 [feat] : 유저는 마이페이지에서 고정 스케줄을 요일별로 조회할 수 있다
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Oct 29, 2024
1 parent 3eb9028 commit fa796c8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 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 @@ -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;
Expand Down Expand Up @@ -81,4 +82,15 @@ public ResponseEntity<ApiResponse<Object>> removeFixedEvent(

return ApiResponse.onSuccess(SuccessStatus._REMOVE_FIXED_SCHEDULE);
}

// 요일별 고정 이벤트 조회 API
@GetMapping("by-day/{day}")
public ResponseEntity<ApiResponse<List<FixedEventByDayResponse>>> getFixedEventByDay(
@RequestHeader("Authorization") String authorizationHeader,
@PathVariable("day") String day) {

List<FixedEventByDayResponse> response = fixedEventService.getFixedEventByDay(authorizationHeader, day);

return ApiResponse.onSuccess(SuccessStatus._GET_FIXED_EVENT_BY_DAY, response);
}
}
Original file line number Diff line number Diff line change
@@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/side/onetime/service/FixedEventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<FixedEventByDayResponse> getFixedEventByDay(String authorizationHeader, String day) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
String koreanDay = convertDayToKorean(day);

List<FixedEvent> 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);
};
}
}

0 comments on commit fa796c8

Please sign in to comment.