Skip to content

Commit

Permalink
Merge pull request #151 from CoolPeace-yanolza/develop
Browse files Browse the repository at this point in the history
01.20 2차 배포
  • Loading branch information
tkddn204 authored Jan 19, 2024
2 parents e524cba + c5524de commit 0e0420e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public record CouponUpdateRequest(
Long accommodationId,
@ValidEnum(enumClass = CustomerType.class, message = "올바르지 않은 고객의 유형입니다.", required = false)
String customerType,
@ValidEnum(enumClass = DiscountType.class, message = "올바르지 않은 고객의 유형입니다.", required = false)
@ValidEnum(enumClass = DiscountType.class, message = "올바르지 않은 할인의 유형입니다.", required = false)
String discountType,
Integer discountValue,
@ValidEnum(enumClass = CouponRoomType.class, message = "올바르지 않은 고객의 유형입니다.", required = false)
@ValidEnum(enumClass = CouponRoomType.class, message = "올바르지 않은 객실의 유형입니다.", required = false)
String couponRoomType,
Boolean registerAllRoom,
List<String> registerRooms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.coolpeace.global.common.ValuedEnum;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.util.StringUtils;

public class ValuedEnumValidator implements ConstraintValidator<ValidEnum, String> {
private Class<? extends Enum<?>> enumClass;
Expand All @@ -17,8 +18,8 @@ public void initialize(ValidEnum constraintAnnotation)

@Override
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
ValuedEnum[] enumValues = (ValuedEnum[]) this.enumClass.getEnumConstants();
if (enumValues != null) {
if (StringUtils.hasText(value)) {
ValuedEnum[] enumValues = (ValuedEnum[]) this.enumClass.getEnumConstants();
// 값이 있으면 무조건 검사 후 유효하면 통과, 유효하지 않으면 실패
for (ValuedEnum enumValue : enumValues) {
if (enumValue.getValue().equals(value)) {
Expand Down

0 comments on commit 0e0420e

Please sign in to comment.