-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
199 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/ac/knu/likeknu/converter/OperatingDaysConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ac.knu.likeknu.converter; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
|
||
import java.time.DayOfWeek; | ||
import java.util.Arrays; | ||
import java.util.EnumSet; | ||
import java.util.stream.Collectors; | ||
|
||
@Converter | ||
public class OperatingDaysConverter implements AttributeConverter<EnumSet<DayOfWeek>, String> { | ||
|
||
private static final String SEPARATOR = ","; | ||
|
||
@Override | ||
public String convertToDatabaseColumn(EnumSet<DayOfWeek> attribute) { | ||
if (attribute == null) { | ||
return null; | ||
} | ||
|
||
return attribute.stream() | ||
.map(Enum::name) | ||
.collect(Collectors.joining(SEPARATOR)); | ||
} | ||
|
||
@Override | ||
public EnumSet<DayOfWeek> convertToEntityAttribute(String dbData) { | ||
EnumSet<DayOfWeek> dayOfWeeks = EnumSet.noneOf(DayOfWeek.class); | ||
if (dbData == null || dbData.isEmpty()) { | ||
return dayOfWeeks; | ||
} | ||
|
||
Arrays.stream(dbData.split(SEPARATOR)) | ||
.forEach(s -> dayOfWeeks.add(DayOfWeek.valueOf(s))); | ||
return dayOfWeeks; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/ac/knu/likeknu/domain/constants/ShuttleOperatingDays.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ac.knu.likeknu.domain.constants; | ||
|
||
public enum ShuttleOperatingDays { | ||
|
||
WEEKDAY, | ||
WEEKEND, | ||
MONDAY, | ||
TUESDAY, | ||
WEDNESDAY, | ||
THURSDAY, | ||
FRIDAY, | ||
SATURDAY, | ||
SUNDAY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ac.knu.likeknu.utils; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.util.EnumSet; | ||
|
||
public class DateTimeUtils { | ||
|
||
public static LocalDate getEarliestNextAvailableDate(EnumSet<DayOfWeek> availableDayOfWeeks) { | ||
LocalDate date = LocalDate.now(); | ||
while (true) { | ||
date = date.plusDays(1); | ||
DayOfWeek dayOfWeek = date.getDayOfWeek(); | ||
if (availableDayOfWeeks.contains(dayOfWeek)) { | ||
return date; | ||
} | ||
} | ||
} | ||
|
||
public static boolean isAnotherWeek(LocalDate date1, LocalDate date2) { | ||
if (date1.isAfter(date2)) { | ||
return date1.getDayOfWeek().getValue() <= date2.getDayOfWeek().getValue(); | ||
} | ||
return date2.getDayOfWeek().getValue() <= date1.getDayOfWeek().getValue(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/db/migration/mysql/V10__add_shuttle_operating_days_columns.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE shuttle | ||
ADD COLUMN operating_days | ||
SET ('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY') | ||
DEFAULT 'MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY'; |