-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
6d27648
commit 347eb85
Showing
14 changed files
with
199 additions
and
95 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
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
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/codezap/category/dto/request/validation/DuplicateId.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,21 @@ | ||
package codezap.category.dto.request.validation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = DuplicateIdValidator.class) | ||
public @interface DuplicateId { | ||
|
||
String message(); | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/codezap/category/dto/request/validation/DuplicateIdValidator.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,18 @@ | ||
package codezap.category.dto.request.validation; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
public class DuplicateIdValidator implements ConstraintValidator<DuplicateId, ValidatedDuplicateIdRequest> { | ||
|
||
@Override | ||
public boolean isValid(ValidatedDuplicateIdRequest request, | ||
ConstraintValidatorContext constraintValidatorContext | ||
) { | ||
List<Long> ids = request.extractIds(); | ||
return ids.size() == new HashSet<>(ids).size(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/codezap/category/dto/request/validation/DuplicateName.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,21 @@ | ||
package codezap.category.dto.request.validation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = DuplicateNameValidator.class) | ||
public @interface DuplicateName { | ||
|
||
String message(); | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/codezap/category/dto/request/validation/DuplicateNameValidator.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 codezap.category.dto.request.validation; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
public class DuplicateNameValidator implements ConstraintValidator<DuplicateName, ValidatedDuplicateNameRequest> { | ||
@Override | ||
public boolean isValid(ValidatedDuplicateNameRequest request, | ||
ConstraintValidatorContext constraintValidatorContext | ||
) { | ||
List<String> names = request.extractNames(); | ||
return names.size() == new HashSet<>(names).size(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...nd/src/main/java/codezap/category/dto/request/validation/ValidatedDuplicateIdRequest.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,11 @@ | ||
package codezap.category.dto.request.validation; | ||
|
||
import java.util.List; | ||
|
||
import codezap.global.validation.ValidationGroups.DuplicateIdGroup; | ||
|
||
@DuplicateId(message = "id가 중복되었습니다.", groups = DuplicateIdGroup.class) | ||
public interface ValidatedDuplicateIdRequest { | ||
|
||
List<Long> extractIds(); | ||
} |
11 changes: 11 additions & 0 deletions
11
.../src/main/java/codezap/category/dto/request/validation/ValidatedDuplicateNameRequest.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,11 @@ | ||
package codezap.category.dto.request.validation; | ||
|
||
import java.util.List; | ||
|
||
import codezap.global.validation.ValidationGroups.DuplicateNameGroup; | ||
|
||
@DuplicateName(message = "카테고리명이 중복되었습니다.", groups = DuplicateNameGroup.class) | ||
public interface ValidatedDuplicateNameRequest { | ||
|
||
List<String> extractNames(); | ||
} |
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
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
Oops, something went wrong.