Skip to content

Commit

Permalink
refactor: DayOfWeekUtil 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuuyeonho committed Feb 4, 2025
1 parent 75b096c commit 732ab37
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.keunsori.keunsoriserver.domain.admin.reservation.dto.request;

import com.keunsori.keunsoriserver.domain.admin.reservation.domain.WeeklySchedule;
import com.keunsori.keunsoriserver.global.util.DayOfWeekUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
Expand All @@ -21,16 +22,11 @@ public record WeeklyScheduleUpdateRequest(
) {
public WeeklySchedule toEntity(){
return WeeklySchedule.builder()
.dayOfWeek(DayOfWeek.of((convertToDowValue(dayOfWeekNum))))
.dayOfWeek(DayOfWeekUtil.fromCustomValue(dayOfWeekNum))
.isActive(isActive)
.startTime(startTime)
.endTime(endTime)
.build();
}

private int convertToDowValue(int dayOfWeekNum){
if(dayOfWeekNum == 0) dayOfWeekNum = 7;
return dayOfWeekNum;
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.keunsori.keunsoriserver.domain.admin.reservation.dto.response;

import com.keunsori.keunsoriserver.domain.admin.reservation.domain.WeeklySchedule;
import com.keunsori.keunsoriserver.global.util.DayOfWeekUtil;

import java.time.LocalTime;

Expand All @@ -12,7 +13,7 @@ public record WeeklyScheduleResponse(
) {
public static WeeklyScheduleResponse from(WeeklySchedule weeklySchedule){
return new WeeklyScheduleResponse(
weeklySchedule.getDayOfWeek().getValue()%7,
DayOfWeekUtil.getCustomValue(weeklySchedule.getDayOfWeek()),
weeklySchedule.isActive(),
weeklySchedule.getStartTime(),
weeklySchedule.getEndTime()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.keunsori.keunsoriserver.global.util;

import java.time.DayOfWeek;

public class DayOfWeekUtil {
public static int getCustomValue(DayOfWeek dayOfWeek){
return dayOfWeek.getValue() % 7;
}

public static DayOfWeek fromCustomValue(int customValue){
return DayOfWeek.of((customValue == 0) ? 7 : customValue);
}
}

0 comments on commit 732ab37

Please sign in to comment.