|
2 | 2 |
|
3 | 3 | import com.ggang.be.api.common.ResponseError;
|
4 | 4 | import com.ggang.be.api.exception.GongBaekException;
|
| 5 | +import com.ggang.be.api.user.vo.TimeTableVo; |
5 | 6 | import com.ggang.be.domain.constant.WeekDay;
|
6 |
| -import lombok.extern.slf4j.Slf4j; |
7 |
| - |
8 | 7 | import java.time.LocalDate;
|
| 8 | +import java.util.List; |
| 9 | +import lombok.extern.slf4j.Slf4j; |
9 | 10 |
|
10 | 11 | @Slf4j
|
11 | 12 | public class TimeValidator {
|
12 |
| - public static void isWeekDateRight(WeekDay writeWeekDay, LocalDate writeDate) { |
| 13 | + |
| 14 | + public static void isWeekDateRight(WeekDay writeWeekDay, LocalDate writeDate) { |
13 | 15 | WeekDay realWeekDay = WeekDay.fromDayOfWeek(writeDate.getDayOfWeek());
|
14 |
| - if(!realWeekDay.equals(writeWeekDay)) { |
| 16 | + if (!realWeekDay.equals(writeWeekDay)) { |
15 | 17 | log.error("weekDate and weekDay is not same");
|
16 | 18 | throw new GongBaekException(ResponseError.BAD_REQUEST);
|
17 | 19 | }
|
18 | 20 | }
|
19 | 21 |
|
20 |
| - public static void isTimeValid(double startTime, double endTime){ |
21 |
| - if((startTime < 9 || startTime >= 18) && (endTime > 18 || endTime <= 9)) { |
| 22 | + public static void isTimeValid(double startTime, double endTime) { |
| 23 | + if ((startTime < 9 || startTime >= 18) || (endTime > 18 || endTime <= 9)) { |
22 | 24 | log.error("startTime {} or endTime {} is not valid", startTime, endTime);
|
23 | 25 | throw new GongBaekException(ResponseError.BAD_REQUEST);
|
24 | 26 | }
|
25 |
| - if(startTime >= endTime) { |
| 27 | + if (startTime >= endTime) { |
26 | 28 | log.error("startTime or endTime is not valid");
|
27 | 29 | throw new GongBaekException(ResponseError.BAD_REQUEST);
|
28 | 30 | }
|
29 | 31 | }
|
30 | 32 |
|
31 |
| - public static void isDateBeforeNow(LocalDate writeDate){ |
32 |
| - if(writeDate.isBefore(LocalDate.now())) { |
| 33 | + public static void isYearAfterNow(int year) { |
| 34 | + if (year > LocalDate.now().getYear()) { |
| 35 | + log.error("year {} is after now {}", year, LocalDate.now().getYear()); |
| 36 | + throw new GongBaekException(ResponseError.BAD_REQUEST); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + public static void isDateBeforeNow(LocalDate writeDate) { |
| 41 | + if (writeDate.isBefore(LocalDate.now())) { |
33 | 42 | log.error("writeDate {} is before now {}", writeDate, LocalDate.now());
|
34 | 43 | throw new GongBaekException(ResponseError.BAD_REQUEST);
|
35 | 44 | }
|
36 | 45 | }
|
37 | 46 |
|
38 | 47 | public static void isSameDate(LocalDate date, LocalDate otherDate) {
|
39 |
| - if(!date.equals(otherDate)) { |
| 48 | + if (!date.equals(otherDate)) { |
40 | 49 | log.error("localDate {} and otherDate {} is not same", date, otherDate);
|
41 | 50 | throw new GongBaekException(ResponseError.BAD_REQUEST);
|
42 | 51 | }
|
43 | 52 | }
|
| 53 | + |
| 54 | + public static void hasDuplicateInfo(List<TimeTableVo> timeTableVos) { |
| 55 | + long size = timeTableVos.size(); |
| 56 | + long count = timeTableVos.stream().distinct().count(); |
| 57 | + |
| 58 | + if (size != count) { |
| 59 | + log.error("timeTableVo has duplicate info"); |
| 60 | + throw new GongBaekException(ResponseError.BAD_REQUEST); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + public static void isTimeVoValidTime(List<TimeTableVo> timeTableVos) { |
| 65 | + timeTableVos.forEach( |
| 66 | + timeTableVo -> isTimeValid(timeTableVo.startTime(), |
| 67 | + timeTableVo.endTime()) |
| 68 | + ); |
| 69 | + } |
44 | 70 | }
|
0 commit comments