개발 일기
챔피언 이름 번역
롤 API 호출시 챔피언 이름이 영어로 나왔고 사이트에서는 한글로 표현이 되야 하는데, 이를 플러터/웹 사이트 각각 처리해주지 말고 백엔드에서 처리해주는게 어떻겠냐는 플러터 개발자님의 의견이 있었다. 합리적인 의견인 것 같아서 그렇게 하기로 했다.
그리고 또한 한글로 번역을 했을 때 이를 데이터 베이스에 저장을 해야할지, 그래서 Entity도 리팩터링을 해야할지에 대한 생각도 들었다. 결론적으로 챔피언이 많지 않기 때문에 (해봐야 게임 당 10건) 변환 작업시 많은 시간을 소요할 것 같다고 생각되지 않아서 데이터 베이스에 저장하지 않고 비즈니스 로직에서 변환하는 작업을 해주기로 했다.
https://developer.riotgames.com/docs/lol
위 사이트에서
Latest를 다운받고 압축을 풀면
14.6.1/14.6.1/data/ko_KR
폴더에 champion.json
파일이 있다. 이 파일을
import json
file_path = "{custom file path}"
data = json.load(open(f"{file_path}champion.json"))
properties_data = []
with open(f"{file_path}lolchampion.properties", "w", encoding="utf-8") as f:
for champion in data['data'] :
info = data['data'][champion]
name = info['name']
new_data = f"{champion}={name}\n"
properties_data.append(new_data)
f.write(new_data)
print(properties_data)
이 스크립트를 사용해서 champion.properties 파일로 변환한다.
Aatrox=아트록스
Ahri=아리
Akali=아칼리
...
이렇게 변환이 되는데 이걸 resources에 넣고
private static String getKoChampName(MatchUser matchUser) {
Properties properties = new Properties();
String engChampName = matchUser.getChampionThumbnail().replace("https://ddragon.leagueoflegends.com/cdn/11.1.1/img/champion/", "").replace(".png", "");
String koChampName;
try {
InputStream inputStream = MatchUserResponse.class.getClassLoader().getResourceAsStream("lolchampion.properties");
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
properties = new Properties();
properties.load(reader);
// 이후 properties를 사용하여 작업을 수행합니다.
koChampName = (String) properties.get(engChampName);
} catch (IOException e) {
log.error("properties 파일을 읽어오는데 실패했습니다.\n" + e.getMessage() + "\n" + e.getStackTrace());
koChampName = engChampName;
}
return koChampName;
}
비즈니스 로직에서 다음과 같은 메서드를 작성해서 Response에 챔피언의 한국어 네임을 함께 담아서 보내줄 수 있도록 변경했다.
통합 테스트의 필요성(작성 중)
Verify를 사용해서 테스트 작성
검색 기록 데이터베이스에 기록 되었는지 검증하는 테스트 작성
S3 upload 테스트 작성 - 테스트 순서 정하기
Youtube Upload 구현
HTTPS 설정
Spring Security Oauth2 Redirect를 에러 메시지로 전환
Spring Security Oauth2 Redirect를 에러 메시지로 전환
리팩터링
회원가입 로직 역할과 책임에 맞게 리팩터링
MatchGameConverter 리팩터링 - 성능이슈
Match Game에서 Match User를 만들어주는데 Match User안에서 매번 Property를 불러오면 IO 비용이 많이 들 것 같다는 생각에 위 메서드를 2개로 분리했다.
private static Properties loadProperties(Properties properties) {
try {
InputStream inputStream = MatchUserResponse.class.getClassLoader().getResourceAsStream("lolchampion.properties");
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
properties = new Properties();
properties.load(reader);
} catch (IOException e) {
log.error("properties 파일을 읽어오는데 실패했습니다.\n" + e.getMessage() + "\n" + e.getStackTrace());
}
return properties;
}
private static String getKoChampName(Properties properties, MatchUser matchUser) {
String engChampName = matchUser.getChampionThumbnail().replace("https://ddragon.leagueoflegends.com/cdn/11.1.1/img/champion/", "").replace(".png", "");
String koChampName;
try {
// 이후 properties를 사용하여 작업을 수행합니다.
koChampName = (String) properties.get(engChampName);
} catch (Exception e) {
log.error("properties 파일을 읽어오는데 실패했습니다.\n" + e.getMessage() + "\n" + e.getStackTrace());
koChampName = engChampName;
}
return koChampName;
}
그리고 loadProperties 메서드를 MatchUser
이 아닌 MatchGame
의 toResponse 메서드에서 호출해준다.
public static MatchGameResponse toResponse(MatchGame matchGame) {
Properties properties = loadProperties(new Properties());
return MatchGameResponse.builder()
.gameId(matchGame.getGameId())
.gameCreation(matchGame.getGameCreation())
.gameDuration(matchGame.getGameDuration())
.gameMode(matchGame.getGameMode())
.matchUsers(matchGame.getMatchUsers().stream()
.map(matchUser
-> MatchUserResponse.toResponse(matchUser, properties))
.toList())
.build();
}
LolSearchAdapter < - > BoardService DI - 아키텍처 이슈
'Spring > Error & Review' 카테고리의 다른 글
[겜문철] Dependency Inversion (0) | 2024.04.13 |
---|---|
QueryDSL Join Error 해결 (0) | 2024.03.30 |
통합 테스트의 필요성 (0) | 2024.03.20 |
회원가입 로직 역할과 책임에 맞게 리팩터링 (0) | 2024.03.19 |
Spring에서 JWT을 좀 더 자세히 알아보자! (0) | 2024.02.24 |