-
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
90dd931
commit ac3848f
Showing
48 changed files
with
856 additions
and
387 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
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
51 changes: 51 additions & 0 deletions
51
backend/src/main/java/codezap/category/dto/request/UpdateAllCategoriesRequest.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,51 @@ | ||
package codezap.category.dto.request; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import codezap.category.dto.request.validation.ValidatedDuplicateNameRequest; | ||
import codezap.category.dto.request.validation.ValidatedDuplicateIdRequest; | ||
import codezap.global.validation.ValidationGroups.NotNullGroup; | ||
import codezap.global.validation.ValidatedOrdinalRequest; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record UpdateAllCategoriesRequest( | ||
@Schema(description = "생성할 카테고리 목록") | ||
@Valid | ||
List<CreateCategoryRequest> createCategories, | ||
|
||
@Schema(description = "수정할 카테고리 목록") | ||
@Valid | ||
List<UpdateCategoryRequest> updateCategories, | ||
|
||
@Schema(description = "삭제할 카테고리 목록") | ||
@NotNull(message = "삭제하는 카테고리 ID 목록이 null 입니다.", groups = NotNullGroup.class) | ||
List<Long> deleteCategoryIds | ||
) implements ValidatedOrdinalRequest, ValidatedDuplicateIdRequest, ValidatedDuplicateNameRequest { | ||
@Override | ||
public List<Integer> extractOrdinal() { | ||
return Stream.concat( | ||
createCategories.stream().map(CreateCategoryRequest::ordinal), | ||
updateCategories.stream().map(UpdateCategoryRequest::ordinal) | ||
).sorted().toList(); | ||
} | ||
|
||
@Override | ||
public List<Long> extractIds() { | ||
return Stream.concat( | ||
updateCategories.stream().map(UpdateCategoryRequest::id), | ||
deleteCategoryIds.stream() | ||
).toList(); | ||
} | ||
|
||
@Override | ||
public List<String> extractNames() { | ||
return Stream.concat( | ||
createCategories.stream().map(CreateCategoryRequest::name), | ||
updateCategories.stream().map(UpdateCategoryRequest::name) | ||
).toList(); | ||
} | ||
} |
13 changes: 12 additions & 1 deletion
13
backend/src/main/java/codezap/category/dto/request/UpdateCategoryRequest.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 |
---|---|---|
@@ -1,16 +1,27 @@ | ||
package codezap.category.dto.request; | ||
|
||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
|
||
import codezap.global.validation.ValidationGroups.NotNullGroup; | ||
import codezap.global.validation.ValidationGroups.SizeCheckGroup; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record UpdateCategoryRequest( | ||
@Schema(description = "카테고리 ID", example = "1") | ||
@NotNull(message = "카테고리 ID가 null 입니다.", groups = NotNullGroup.class) | ||
Long id, | ||
|
||
@Schema(description = "카테고리 이름", example = "Spring") | ||
@NotBlank(message = "카테고리 이름이 null 입니다.", groups = NotNullGroup.class) | ||
@Size(max = 15, message = "카테고리 이름은 최대 15자까지 입력 가능합니다.", groups = SizeCheckGroup.class) | ||
String name | ||
String name, | ||
|
||
@Schema(description = "카테고리 순서", example = "1") | ||
@NotNull(message = "카테고리 순서가 null 입니다.", groups = NotNullGroup.class) | ||
@Min(value = 1, message = "카테고리의 순서는 1 이상이어야 합니다.") | ||
Integer ordinal | ||
) { | ||
} |
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
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(); | ||
} |
Oops, something went wrong.