Skip to content

Feat/#377 금칙어 필터링 구현#384

Open
dev-domo wants to merge 8 commits intodevelopfrom
feat/#377-forbiddenWord
Open

Feat/#377 금칙어 필터링 구현#384
dev-domo wants to merge 8 commits intodevelopfrom
feat/#377-forbiddenWord

Conversation

@dev-domo
Copy link
Collaborator

🔗 연결된 이슈

📄 작업 내용

  • 금칙어 목록 필터링을 구현했습니다.
  • 추가로 닉네임 관련해서 추가 통제 단어(admin, master, test, 운영자, 관리자) 필터링도 구현했습니다.
구현 내용 IPhone 16 pro IPhone 13 mini
닉네임 입력
닉네임 수정

💻 주요 코드 설명

ForbiddenRepository

  • 금칙어 목록을 json 파일로 만들어보았어요.
  • json 파일에서 데이터를 읽어들이는 행위를 Data 영역의 책임이라고 판단했습니다.
  • 또한 레포지토리를 호출할 때마다 json 파일을 읽어들이는 것은 비효율적이기 때문에, 일종의 캐시를 적용했습니다.
final class DefaultForbiddenWordRepository: ForbiddenWordInterface {
    
    private let resource = "ForbiddenWords"
    private let fileExtension = "json"
    // 로드된 금칙어 목록 저장
    private var cachedForbiddenWords: ForbiddenWordEntity?
    
    func getForbiddenWords(_ word: String) -> ForbiddenWordEntity? {
       // 캐시된 데이터가 있다면 이를 리턴
        if let cached = cachedForbiddenWords {
            return cached
        }
        
        guard let url = fetchURL(),
              let forbiddenWordList = decodeForbiddenWords(url: url) else {
            return nil
        }
        
        let forbiddenWordEntity = forbiddenWordList.toEntity()
        cachedForbiddenWords = forbiddenWordEntity
        return forbiddenWordEntity
    }
    
    private func fetchURL() -> URL? {
        guard let url = Bundle.main.url(forResource: resource, withExtension: fileExtension) else {
            ByeBooLogger.error(ByeBooError.fileNotFound)
            return nil
        }
        
        return url
    }
    
    private func decodeForbiddenWords(url: URL) -> ForbiddenWordList? {
        do {
            let data = try Data(contentsOf: url)
            let decoder = JSONDecoder()
            let decodedData = try decoder.decode(ForbiddenWordList.self, from: data)
            return decodedData
        } catch {
            ByeBooLogger.error(ByeBooError.decodingError)
            return nil
        }
    }
}

NicknameRule

  • admin, master 등 닉네임으로 설정하면 안 되는 단어들이 있는데요, 이건 기존의 NicknameRule에 추가했습니다.
enum NicknameRule {
    private static let regularExpression = "(?=.{2,5}$)(?!.*[ㄱ-ㅎㅏ-ㅣ])[가-힣a-zA-Z0-9]+"
    static let predicate = NSPredicate(format: "SELF MATCHES %@", regularExpression)
    // 닉네임 설정 불가 단어
    static let bannedWords: Set<String> = ["admin", "master", "test", "운영자", "관리자"]
}

@dev-domo dev-domo self-assigned this Feb 28, 2026
@dev-domo dev-domo added 승준🤠 feat 새로운 기능 구현 및 API 연결 labels Feb 28, 2026
@dev-domo dev-domo linked an issue Feb 28, 2026 that may be closed by this pull request
1 task
Copy link
Collaborator

@y-eonee y-eonee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

선생님이 10알 이라는 단어를 쓰는게 웃겨요

enum NicknameRule {
private static let regularExpression = "(?=.{2,5}$)(?!.*[ㄱ-ㅎㅏ-ㅣ])[가-힣a-zA-Z0-9]+"
static let predicate = NSPredicate(format: "SELF MATCHES %@", regularExpression)
static let bannedWords: Set<String> = ["admin", "master", "test", "운영자", "관리자"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋다잉

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트코드까지..? 개맹 그는 어디까지 맹수일것인가

Comment on lines +31 to +36
private func fetchURL() -> URL? {
guard let url = Bundle.main.url(forResource: resource, withExtension: fileExtension) else {
ByeBooLogger.error(ByeBooError.fileNotFound)
return nil
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메모리에 저장되어있는 파일을 캐싱해오는건가용? 오

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat 새로운 기능 구현 및 API 연결 승준🤠

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Feat] 불가 단어 입력 에러케이스 처리

2 participants