Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOTFIX] : 요일 별 고정 스케줄 조회 시 시간 오류를 해결하기 위한 긴급 배포 #134

Merged
merged 6 commits into from
Dec 10, 2024
20 changes: 2 additions & 18 deletions src/main/java/side/onetime/domain/FixedEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,16 @@ public class FixedEvent extends BaseEntity {
@Column(name = "title", nullable = false, length = 30)
private String title;

@Column(name = "start_time", nullable = false)
private String startTime;

@Column(name = "end_time", nullable = false)
private String endTime;

@OneToMany(mappedBy = "fixedEvent",cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<FixedSelection> fixedSelections;

@Builder
public FixedEvent(User user, String title, String startTime, String endTime) {
public FixedEvent(User user, String title) {
this.user = user;
this.title = title;
this.startTime = startTime;
this.endTime = endTime;
}

public void updateTitle(String title) {
this.title = title;
}

public void updateStartTime(String startTime) {
this.startTime = startTime;
}

public void updateEndTime(String endTime) {
this.endTime = endTime;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@

import java.util.List;

import static side.onetime.util.DateUtil.addThirtyMinutes;

@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public record CreateFixedEventRequest(
@NotBlank(message = "제목은 필수 값입니다.") String title,
@NotNull(message = "스케줄 목록은 필수 값입니다.") List<FixedScheduleResponse> schedules
) {
public FixedEvent toEntity(User user, String startTime, String endTime) {
public FixedEvent toEntity(User user) {
return FixedEvent.builder()
.user(user)
.title(title)
.startTime(startTime)
.endTime(addThirtyMinutes(endTime))
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import side.onetime.domain.FixedEvent;
import side.onetime.domain.User;
import side.onetime.dto.fixed.response.FixedScheduleResponse;

import java.util.List;

import static side.onetime.util.DateUtil.addThirtyMinutes;

@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public record ModifyFixedEventRequest(
String title,
List<FixedScheduleResponse> schedules
) {
public FixedEvent toEntity(User user, String startTime, String endTime) {
return FixedEvent.builder()
.user(user)
.title(title)
.startTime(startTime)
.endTime(addThirtyMinutes(endTime))
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
@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) {
public static FixedEventDetailResponse of(String title, List<FixedScheduleResponse> schedules) {
return new FixedEventDetailResponse(
title,
startTime,
endTime,
schedules
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
public record FixedEventResponse(
Long id,
String startTime,
String endTime,
List<FixedScheduleResponse> schedules
) {
public static FixedEventResponse of(Long id, String startTime, String endTime, List<FixedScheduleResponse> schedules) {
public static FixedEventResponse of(Long id, List<FixedScheduleResponse> schedules) {
return new FixedEventResponse(
id,
startTime,
endTime,
schedules
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public interface FixedEventRepositoryCustom {
FixedEvent findByUserAndFixedEventIdCustom(User user, Long fixedEventId);
void deleteFixedEventAndSelections(User user, Long fixedEventId);
List<FixedEvent> findFixedEventsByUserAndDay(User user, String day);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ public List<FixedEvent> findFixedEventsByUserAndDay(User user, String day) {
.and(fixedSchedule.day.eq(day)))
.fetch();
}

}
}
82 changes: 63 additions & 19 deletions src/main/java/side/onetime/service/FixedEventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import side.onetime.domain.FixedEvent;
import side.onetime.domain.FixedSelection;
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;
import side.onetime.util.DateUtil;
import side.onetime.util.JwtUtil;

import java.util.Comparator;
import java.util.List;


Expand All @@ -23,19 +26,32 @@ public class FixedEventService {
private final FixedEventRepository fixedEventRepository;
private final JwtUtil jwtUtil;

// 고정 이벤트 생성 메서드
/**
* 고정 이벤트 생성 메서드.
*
* 유저 인증 정보를 기반으로 새로운 고정 이벤트를 생성하고,
* 관련된 고정 스케줄을 등록합니다.
*
* @param authorizationHeader 인증 토큰
* @param createFixedEventRequest 고정 이벤트 생성 요청 데이터
*/
@Transactional
public void createFixedEvent(String authorizationHeader, CreateFixedEventRequest createFixedEventRequest) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
List<String> times = createFixedEventRequest.schedules().get(0).times();
String startTime = times.get(0);
String endTime = times.get(times.size() - 1);
FixedEvent fixedEvent = createFixedEventRequest.toEntity(user, startTime, endTime);
FixedEvent fixedEvent = createFixedEventRequest.toEntity(user);
fixedEventRepository.save(fixedEvent);
fixedScheduleService.createFixedSchedules(createFixedEventRequest.schedules(), fixedEvent);
}

// 고정 이벤트 수정 메서드
/**
* 고정 이벤트 수정 메서드.
*
* 고정 이벤트의 제목을 수정합니다.
*
* @param authorizationHeader 인증 토큰
* @param fixedEventId 수정할 고정 이벤트 ID
* @param modifyFixedEventRequest 고정 이벤트 수정 요청 데이터
*/
@Transactional
public void modifyFixedEvent(String authorizationHeader, Long fixedEventId, ModifyFixedEventRequest modifyFixedEventRequest) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
Expand All @@ -45,7 +61,14 @@ public void modifyFixedEvent(String authorizationHeader, Long fixedEventId, Modi
fixedEventRepository.save(fixedEvent);
}

// 고정 이벤트 & 스케줄 삭제 메서드
/**
* 고정 이벤트 및 관련 스케줄 삭제 메서드.
*
* 고정 이벤트와 해당 이벤트에 관련된 모든 스케줄을 삭제합니다.
*
* @param authorizationHeader 인증 토큰
* @param fixedEventId 삭제할 고정 이벤트 ID
*/
@Transactional
public void removeFixedEvent(String authorizationHeader, Long fixedEventId) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
Expand All @@ -54,25 +77,46 @@ public void removeFixedEvent(String authorizationHeader, Long fixedEventId) {
fixedEventRepository.deleteFixedEventAndSelections(user, fixedEventId);
}

// 요일 별 고정 이벤트 조회 메서드
/**
* 요일별 고정 이벤트 조회 메서드.
*
* 특정 요일에 해당하는 고정 이벤트 목록을 조회합니다.
* startTime을 기준으로 오름차순 정렬하여 반환합니다.
*
* @param authorizationHeader 인증 토큰
* @param day 조회할 요일 (예: "mon", "tue" 등)
* @return 고정 이벤트 목록 (startTime 기준 오름차순 정렬)
*/
@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()
))
return fixedEventRepository.findFixedEventsByUserAndDay(user, koreanDay).stream()
.map(fixedEvent -> {
List<FixedSelection> fixedSelections = fixedEvent.getFixedSelections();
String startTime = fixedSelections.get(0).getFixedSchedule().getTime();
String endTime = fixedSelections.get(fixedSelections.size() - 1).getFixedSchedule().getTime();
return FixedEventByDayResponse.of(
fixedEvent.getId(),
fixedEvent.getTitle(),
startTime,
DateUtil.addThirtyMinutes(endTime)
);
})
.sorted(Comparator.comparing(FixedEventByDayResponse::startTime))
.toList();
}

// 영어 요일 -> 한글 요일 변환 메서드
/**
* 영어 요일 -> 한글 요일 변환 메서드.
*
* 영어로 입력된 요일을 한글 요일로 변환합니다.
* 입력이 올바르지 않을 경우 예외를 발생시킵니다.
*
* @param day 영어 요일 (예: "mon", "tue" 등)
* @return 한글 요일 (예: "월", "화" 등)
*/
private String convertDayToKorean(String day) {
return switch (day.toLowerCase()) {
case "mon" -> "월";
Expand All @@ -85,4 +129,4 @@ private String convertDayToKorean(String day) {
default -> throw new CustomException(FixedErrorStatus._IS_NOT_RIGHT_DAY);
};
}
}
}
Loading
Loading