-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from HyunJunSon/feature/badwordfiltering
Feature:: 비속어 필터링 기능 추가
- Loading branch information
Showing
10 changed files
with
88 additions
and
7 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
23 changes: 23 additions & 0 deletions
23
module-api/src/main/java/com/kernel360/global/annotation/BadWordFilter.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,23 @@ | ||
package com.kernel360.global.annotation; | ||
|
||
import com.kernel360.global.badwordfilter.BadWordValidator; | ||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.*; | ||
|
||
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Constraint(validatedBy = BadWordValidator.class) | ||
public @interface BadWordFilter { | ||
String message() default ""; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
boolean ignoreCase() default false; | ||
} |
33 changes: 33 additions & 0 deletions
33
module-api/src/main/java/com/kernel360/global/badwordfilter/BadWordValidator.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 com.kernel360.global.badwordfilter; | ||
|
||
import com.kernel360.global.annotation.BadWordFilter; | ||
import com.vane.badwordfiltering.BadWordFiltering; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
import java.util.List; | ||
|
||
public class BadWordValidator implements ConstraintValidator<BadWordFilter, Object> { | ||
private BadWordFiltering badWordFiltering; | ||
@Override | ||
public void initialize(BadWordFilter constraintAnnotation) { | ||
|
||
badWordFiltering = new BadWordFiltering(); | ||
} | ||
|
||
@Override | ||
public boolean isValid(Object value, ConstraintValidatorContext context) { | ||
if (value instanceof String string) { | ||
return !badWordFiltering.check(string); | ||
} else if (value instanceof List<?> list) { | ||
return handleStringList(list); | ||
} | ||
return true; | ||
} | ||
|
||
private boolean handleStringList(List<?> list) { | ||
return list.stream() | ||
.map(String.class::cast) | ||
.noneMatch(badWordFiltering::check); | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
module-api/src/main/java/com/kernel360/member/repository/MemberRepository.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,5 +1,3 @@ | ||
package com.kernel360.member.repository; | ||
|
||
|
||
public interface MemberRepository extends MemberRepositoryJpa { | ||
} |
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
7 changes: 7 additions & 0 deletions
7
module-domain/src/main/java/com/kernel360/member/repository/AdminRepository.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,7 @@ | ||
package com.kernel360.member.repository; | ||
|
||
import com.kernel360.member.entity.Admin; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AdminRepository extends JpaRepository<Admin,Long> { | ||
} |