-
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.
Browse files
Browse the repository at this point in the history
#41 Feat: 시간 Validator 구현
- Loading branch information
Showing
6 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/leets/weeth/domain/schedule/application/annotation/ScheduleTimeCheck.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,28 @@ | ||
package leets.weeth.domain.schedule.application.annotation; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
import leets.weeth.domain.schedule.application.validator.ScheduleTimeCheckValidator; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Target({FIELD}) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = ScheduleTimeCheckValidator.class) | ||
public @interface ScheduleTimeCheck { | ||
|
||
String message() default "마감 시간이 시작 시간보다 빠를 수 없습니다."; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
String matchStartTime() default "matchStartTime"; | ||
|
||
String matchEndTime() default "matchEndTime"; | ||
|
||
} |
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
19 changes: 19 additions & 0 deletions
19
...in/java/leets/weeth/domain/schedule/application/validator/ScheduleTimeCheckValidator.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,19 @@ | ||
package leets.weeth.domain.schedule.application.validator; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import leets.weeth.domain.schedule.application.annotation.ScheduleTimeCheck; | ||
import leets.weeth.domain.schedule.application.dto.ScheduleDTO.Time; | ||
|
||
public class ScheduleTimeCheckValidator implements ConstraintValidator<ScheduleTimeCheck, Time> { | ||
|
||
@Override | ||
public void initialize(ScheduleTimeCheck constraintAnnotation) { | ||
ConstraintValidator.super.initialize(constraintAnnotation); | ||
} | ||
|
||
@Override | ||
public boolean isValid(Time time, ConstraintValidatorContext context) { | ||
return time.start().isBefore(time.end().plusMinutes(1)); | ||
} | ||
} |
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