-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
35 changed files
with
928 additions
and
188 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
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/sports/server/command/report/application/ReportProcessor.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,34 @@ | ||
package com.sports.server.command.report.application; | ||
|
||
import com.sports.server.command.cheertalk.domain.CheerTalk; | ||
import com.sports.server.command.report.domain.Report; | ||
import com.sports.server.common.application.TextFileProcessor; | ||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ReportProcessor { | ||
|
||
private final TextFileProcessor textFileProcessor; | ||
private static final String FILE_NAME = "static/extra_bad_words.txt"; | ||
private static final String DELIM = ","; | ||
|
||
private Set<String> cachedBadWords; | ||
|
||
public void check(CheerTalk cheerTalk, Report report) { | ||
|
||
if (cachedBadWords == null) { | ||
cachedBadWords = textFileProcessor.readFile(FILE_NAME, DELIM); | ||
} | ||
|
||
if (cachedBadWords.contains(cheerTalk.getContent())) { | ||
report.updateToValid(); | ||
return; | ||
} | ||
report.updateToPending(); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/sports/server/common/application/TextFileProcessor.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,38 @@ | ||
package com.sports.server.common.application; | ||
|
||
import com.sports.server.common.exception.CustomException; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class TextFileProcessor { | ||
|
||
public Set<String> readFile(String fileName, String delim) { | ||
ClassPathResource resource = new ClassPathResource(fileName); | ||
|
||
Set<String> resultSet = new HashSet<>(); | ||
try (BufferedReader reader = new BufferedReader( | ||
new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) { | ||
|
||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
String[] tokens = line.split(delim); | ||
for (String token : tokens) { | ||
resultSet.add(token.replaceAll("^[\\s'\"]+|[\\s'\"]+$", "")); | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new CustomException(HttpStatus.INTERNAL_SERVER_ERROR, "파일을 읽어들이는 도중 예외가 발생했습니다."); | ||
} | ||
return resultSet; | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.