From c4546e3ddf34eb5a64eefbef863d28a9c13cf229 Mon Sep 17 00:00:00 2001 From: hellozo0 Date: Wed, 17 Jan 2024 04:09:03 +0900 Subject: [PATCH] =?UTF-8?q?#143=20[fix]=20preferRegion=20=EA=B0=92=20Valid?= =?UTF-8?q?ation=20=ED=95=A8=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prefer_regions/PreferRegionsValidator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/moddy/server/common/validation/prefer_regions/PreferRegionsValidator.java b/src/main/java/com/moddy/server/common/validation/prefer_regions/PreferRegionsValidator.java index a407eded..4116b2d2 100644 --- a/src/main/java/com/moddy/server/common/validation/prefer_regions/PreferRegionsValidator.java +++ b/src/main/java/com/moddy/server/common/validation/prefer_regions/PreferRegionsValidator.java @@ -3,6 +3,7 @@ import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; +import java.util.HashSet; import java.util.List; public class PreferRegionsValidator implements ConstraintValidator> { @@ -14,9 +15,11 @@ public void initialize(ValidPreferRegions constraintAnnotation) { @Override public boolean isValid(List preferRegions, ConstraintValidatorContext context) { - if(preferRegions.size() > 3) return false; - if(preferRegions.stream().filter(p -> p == 0).count() > 1) return false; - if(!preferRegions.stream().allMatch(p -> p >= 0 && p <= 25)) return false; + if (preferRegions.size() != new HashSet<>(preferRegions).size()) return false; + if (preferRegions.stream().filter(p -> p == 0).count() <= 1 && preferRegions.stream().anyMatch(p -> p != 0)) return false; + if (!preferRegions.stream().allMatch(p -> p >= 0 && p <= 25)) return false; + if (preferRegions.size() > 3 ) return false; + return true; }