-
Notifications
You must be signed in to change notification settings - Fork 11
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
5 changed files
with
62 additions
and
10 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
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
17 changes: 17 additions & 0 deletions
17
...in/java/javalab/umc7th_mission/study/validation/annotation/IsMemberMissionNotStarted.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,17 @@ | ||
package javalab.umc7th_mission.study.validation.annotation; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
import javalab.umc7th_mission.study.validation.validatior.IsMemberMissionNotStartedValidator; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Constraint(validatedBy = IsMemberMissionNotStartedValidator.class) | ||
@Target( { ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface IsMemberMissionNotStarted { | ||
String message() default "해당 미션은 이미 진행중입니다."; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
33 changes: 33 additions & 0 deletions
33
...avalab/umc7th_mission/study/validation/validatior/IsMemberMissionNotStartedValidator.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,33 @@ | ||
package javalab.umc7th_mission.study.validation.validatior; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; | ||
import javalab.umc7th_mission.study.service.MemberMissionService.MemberMissionCommandService; | ||
import javalab.umc7th_mission.study.validation.annotation.IsMemberMissionNotStarted; | ||
import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionRequestDTO; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class IsMemberMissionNotStartedValidator implements ConstraintValidator<IsMemberMissionNotStarted, MemberMissionRequestDTO.AddMemberMissionDto> { | ||
private final MemberMissionCommandService memberMissionCommandService; | ||
@Override | ||
public void initialize(IsMemberMissionNotStarted constraintAnnotation) { | ||
ConstraintValidator.super.initialize(constraintAnnotation); | ||
} | ||
|
||
@Override | ||
public boolean isValid(MemberMissionRequestDTO.AddMemberMissionDto request, ConstraintValidatorContext context) { | ||
boolean isValid = memberMissionCommandService.isExist(request.getMemberId(), request.getMissionId()); | ||
|
||
if(isValid){ | ||
context.disableDefaultConstraintViolation(); | ||
context.buildConstraintViolationWithTemplate(ErrorStatus.MEMBER_MISSION_ALREADY_IN_CHALLENGING.toString()).addConstraintViolation(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...ain/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.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