Skip to content

Commit

Permalink
Merge branch 'feature/DRAW-357' into sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
comforest committed Sep 17, 2024
2 parents 3eb1818 + 5d59bce commit abbb7b4
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 23 deletions.
1 change: 1 addition & 0 deletions adapter/firebase/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

dependencies {
implementation(project(":domain"))
implementation(project(":app:support:i18n"))
implementation(project(":support:metric"))

implementation("org.springframework.boot:spring-boot-starter:${Versions.SPRING_BOOT}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package com.xorker.draw.firebase
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.Message
import com.google.firebase.messaging.Notification
import com.xorker.draw.i18n.MessageService
import com.xorker.draw.notification.PushMessageUseCase
import java.util.Locale
import org.springframework.context.MessageSource
import org.springframework.stereotype.Service

@Service
class FcmService(
private val messageSource: MessageSource,
private val messageService: MessageService,
) : PushMessageUseCase {

override fun quickStart(localeStr: String, nickname: String) {
val locale = Locale(localeStr)

val notification = Notification.builder()
.setTitle(messageSource.getMessage("fcm.quickstart.title", null, locale))
.setBody(String.format(messageSource.getMessage("fcm.quickstart.body", null, locale), nickname))
.setTitle(messageService.getMessage("fcm.quickstart.title", locale))
.setBody(String.format(messageService.getMessage("fcm.quickstart.body", locale), nickname))
.build()

val message = Message.builder()
Expand Down

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions app/support/exception/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

dependencies {
implementation(project(":domain"))
implementation(project(":app:support:i18n"))

implementation("org.springframework.boot:spring-boot-starter-web:${Versions.SPRING_BOOT}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.xorker.draw.exception

import com.xorker.draw.exception.ExceptionButtonAction.CloseDialog
import com.xorker.draw.exception.ExceptionButtonAction.ForceUpdate
import com.xorker.draw.i18n.MessageService
import java.util.*
import org.springframework.context.MessageSource

enum class ExceptionButtonType(
private val i18nCode: String,
Expand All @@ -17,10 +17,10 @@ enum class ExceptionButtonType(

private val responseMap = HashMap<Locale, ExceptionButtonResponse>()

fun toResponse(source: MessageSource, locale: Locale): ExceptionButtonResponse {
fun toResponse(source: MessageService, locale: Locale): ExceptionButtonResponse {
if (responseMap.containsKey(locale).not()) {
val response = ExceptionButtonResponse(
text = source.getMessage(this.i18nCode, null, locale),
text = source.getMessage(this.i18nCode, locale),
action = this.action,
)

Expand Down Expand Up @@ -62,6 +62,7 @@ fun XorkerException.getButtons(): List<ExceptionButtonType> {
InvalidRequestOtherPlayingException,
AlreadyPlayingRoomException,
InvalidWebSocketStatusException,
is NotDefinedMessageCodeException,
-> buttonOk
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.xorker.draw.exception

import org.springframework.context.MessageSource
import com.xorker.draw.i18n.MessageService
import org.springframework.context.i18n.LocaleContextHolder
import org.springframework.stereotype.Component

@Component
class ExceptionDesignFactory(
private val messageSource: MessageSource,
private val messageService: MessageService,
) {
fun generate(ex: XorkerException): ExceptionDesign {
return when (ex) {
Expand All @@ -20,19 +20,20 @@ class ExceptionDesignFactory(

private fun generateToast(ex: XorkerException): ToastResponse {
val locale = LocaleContextHolder.getLocale()
val text = messageSource.getMessage("exception.${ex.code}.text", null, "ERROR", locale)
?: messageSource.getMessage("exception.default.description", null, locale)
val text = messageService.getMessageOrNull("exception.${ex.code}.text", locale)
?: messageService.getMessage("exception.default.description", locale)

return ToastResponse(text)
}

private fun generateDialog(ex: XorkerException): DialogResponse {
val locale = LocaleContextHolder.getLocale()

val title = messageSource.getMessage("exception.${ex.code}.title", null, "ERROR", locale) // TODO 기본 에러 처리 하기
val description = messageSource.getMessage("exception.${ex.code}.description", null, null, locale)
?: messageSource.getMessage("exception.default.description", null, locale)
val buttons = ex.getButtons().map { it.toResponse(messageSource, locale) }
val title = messageService.getMessageOrNull("exception.${ex.code}.title", locale) ?: "ERROR" // TODO 기본 에러 처리 하기
val description =
messageService.getMessageOrNull("exception.${ex.code}.description", locale)
?: messageService.getMessage("exception.default.description", locale)
val buttons = ex.getButtons().map { it.toResponse(messageService, locale) }

return DialogResponse(title, description, buttons)
}
Expand Down

This file was deleted.

18 changes: 18 additions & 0 deletions app/support/i18n/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
id("org.springframework.boot")
kotlin("plugin.spring")
}

dependencies {
implementation(project(":domain"))
implementation(project(":support:logging"))

implementation("org.springframework.boot:spring-boot-starter:${Versions.SPRING_BOOT}")
}

tasks {
withType<Jar> { enabled = true }
withType<BootJar> { enabled = false }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.xorker.draw.i18n

import org.springframework.context.MessageSource
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.support.ResourceBundleMessageSource

@Configuration
class MessageConfig {
@Bean
fun messageSource(): MessageSource {
val messageSource = ResourceBundleMessageSource()
messageSource.setDefaultEncoding("UTF-8")
messageSource.setBasename("i18n/messages")
return messageSource
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.xorker.draw.i18n

import com.xorker.draw.exception.NotDefinedMessageCodeException
import com.xorker.draw.support.logging.logger
import java.util.Locale
import org.springframework.context.MessageSource
import org.springframework.context.NoSuchMessageException
import org.springframework.stereotype.Component

@Component
class MessageService(
private val messageSource: MessageSource,
) {
private val logger = logger()

fun getMessage(code: String, locale: Locale): String {
try {
return messageSource.getMessage(code, null, locale)
} catch (e: NoSuchMessageException) {
logger.error("i18n Error - $code", e)
throw NotDefinedMessageCodeException(code, locale, e)
}
}

fun getMessageOrNull(code: String, locale: Locale): String? {
try {
return messageSource.getMessage(code, null, locale)
} catch (e: NoSuchMessageException) {
logger.warn("i18n Error - $code", e)
return null
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
fcm.quickstart.title=🕹️ Quick Start Alarm
fcm.quickstart.body=%s is waiting in a quick match.

exception.default.description='예상치 못한 예외가 발생했습니다.'
exception.button.ok='OK'
exception.button.cancel='Cancel'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
fcm.quickstart.title=🕹️ 빠른 게임 알림
fcm.quickstart.body=%s님이 빠른 게임에서 기다리고 있어요.


exception.default.description='예상치 못한 예외가 발생했습니다.'
exception.button.ok='확인'
exception.button.cancel='취소'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.xorker.draw.exception

import java.util.Locale
import org.springframework.context.NoSuchMessageException

sealed class XorkerException(val code: String, message: String, cause: Throwable? = null) : RuntimeException(message, cause)

//region Client
Expand Down Expand Up @@ -36,4 +39,5 @@ data object UnSupportedException : CriticalException("crt003", "정의하지 않
data object InvalidBroadcastException : CriticalException("crt004", "유효하지 않은 브로드캐스트 상태") { private fun readResolve(): Any = InvalidBroadcastException }
class InvalidMafiaPhaseException(message: String) : CriticalException("crt005", message)
data object InvalidWebSocketStatusException : CriticalException("crt006", "웹 소켓 세션 상태가 유효하지 않음") { private fun readResolve(): Any = InvalidWebSocketStatusException }
class NotDefinedMessageCodeException(messageCode: String, locale: Locale, cause: NoSuchMessageException) : CriticalException("crt007", "정의되지 않은 메시지 코드 $locale $messageCode", cause)
//endregion
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(
"app:api",
"app:support:auth",
"app:support:exception",
"app:support:i18n",
"app:websocket",
"domain",
"core",
Expand Down

0 comments on commit abbb7b4

Please sign in to comment.