diff --git a/common/src/main/kotlin/co/nilin/opex/common/OpexError.kt b/common/src/main/kotlin/co/nilin/opex/common/OpexError.kt index b87761b06..57176f475 100644 --- a/common/src/main/kotlin/co/nilin/opex/common/OpexError.kt +++ b/common/src/main/kotlin/co/nilin/opex/common/OpexError.kt @@ -115,6 +115,7 @@ enum class OpexError(val code: Int, val message: String?, val status: HttpStatus OTPCannotBeRequested(6050, "OTP cannot be requested", HttpStatus.BAD_REQUEST), WithdrawRequestExpired(6051,"Withdraw request expired", HttpStatus.BAD_REQUEST), ForbiddenSwapPair(6052, null, HttpStatus.BAD_REQUEST), + TerminalLocalizationNotFound(6053, "Terminal localization not found", HttpStatus.NOT_FOUND), // code 7000: api diff --git a/common/src/main/kotlin/co/nilin/opex/common/translation/CustomErrorTranslator.kt b/common/src/main/kotlin/co/nilin/opex/common/translation/CustomErrorTranslator.kt index 7db3cf559..1fcffc9d6 100644 --- a/common/src/main/kotlin/co/nilin/opex/common/translation/CustomErrorTranslator.kt +++ b/common/src/main/kotlin/co/nilin/opex/common/translation/CustomErrorTranslator.kt @@ -1,12 +1,12 @@ package co.nilin.opex.common.translation +import co.nilin.opex.common.utils.LanguageUtils.getUserLanguage import co.nilin.opex.utility.error.data.DefaultExceptionResponse import co.nilin.opex.utility.error.data.OpexException import co.nilin.opex.utility.error.spi.ErrorTranslator import co.nilin.opex.utility.error.spi.ExceptionResponse import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service import reactor.core.publisher.Mono @@ -31,9 +31,6 @@ class CustomErrorTranslator() : ErrorTranslator { ) } } - - fun getUserLanguage(): Mono = - Mono.deferContextual { ctx -> Mono.just(ctx.getOrDefault("lang", "EN")!!) } } diff --git a/common/src/main/kotlin/co/nilin/opex/common/utils/LanguageUtils.kt b/common/src/main/kotlin/co/nilin/opex/common/utils/LanguageUtils.kt new file mode 100644 index 000000000..3d03941f8 --- /dev/null +++ b/common/src/main/kotlin/co/nilin/opex/common/utils/LanguageUtils.kt @@ -0,0 +1,12 @@ +package co.nilin.opex.common.utils + +import co.nilin.opex.common.data.UserLanguage +import reactor.core.publisher.Mono + +object LanguageUtils { + + fun getUserLanguage(): Mono = + Mono.deferContextual { ctx -> Mono.just(ctx.getOrDefault("lang", UserLanguage.EN.toString())!!) } + + fun getDefaultUserLanguage(): String = UserLanguage.EN.toString() +} \ No newline at end of file diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/DepositAdminController.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/DepositAdminController.kt index 444c8dd16..64ae66137 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/DepositAdminController.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/DepositAdminController.kt @@ -2,9 +2,12 @@ package co.nilin.opex.wallet.app.controller import co.nilin.opex.wallet.app.dto.AdminSearchDepositRequest import co.nilin.opex.wallet.app.dto.ManualTransferRequest +import co.nilin.opex.wallet.app.dto.TerminalLocalizationRequest +import co.nilin.opex.wallet.app.dto.TerminalLocalizationResponse import co.nilin.opex.wallet.app.service.DepositService import co.nilin.opex.wallet.core.inout.DepositAdminResponse import co.nilin.opex.wallet.core.inout.TerminalCommand +import co.nilin.opex.wallet.core.inout.TerminalLocalizationCommand import co.nilin.opex.wallet.core.inout.TransferResult import co.nilin.opex.wallet.core.spi.TerminalManager import io.swagger.annotations.ApiResponse @@ -139,5 +142,35 @@ class DepositAdminController( terminalManager.fetchTerminal(terminalUuid) } + @PostMapping("/terminal/{uuid}/localization") + suspend fun saveTerminalLocalization( + @PathVariable("uuid") terminalUuid: String, + @RequestBody body: TerminalLocalizationRequest + ): TerminalLocalizationResponse { + val terminalLocalizations = terminalManager.saveTerminalLocalizations(terminalUuid, body.terminalLocalizations) + return TerminalLocalizationResponse(terminalUuid, terminalLocalizations) + } + + @GetMapping("/terminal/{uuid}/localization") + suspend fun getTerminalLocalization( + @PathVariable("uuid") terminalUuid: String + ): TerminalLocalizationResponse { + val terminalLocalizations = terminalManager.fetchTerminalLocalizations(terminalUuid) + return TerminalLocalizationResponse(terminalUuid, terminalLocalizations) + } + + @DeleteMapping("/terminal/localization/{id}") + suspend fun deleteTerminalLocalization( + @PathVariable("id") id: Long, + ) { + terminalManager.deleteTerminalLocalizations(id) + } + + @PutMapping("/terminal/localization") + suspend fun updateTerminalLocalization( + @RequestBody body: TerminalLocalizationCommand + ): TerminalLocalizationCommand { + return terminalManager.updateTerminalLocalization(body) + } } \ No newline at end of file diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/TerminalLocalizationRequest.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/TerminalLocalizationRequest.kt new file mode 100644 index 000000000..c4622eee5 --- /dev/null +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/TerminalLocalizationRequest.kt @@ -0,0 +1,7 @@ +package co.nilin.opex.wallet.app.dto + +import co.nilin.opex.wallet.core.inout.TerminalLocalizationCommand + +data class TerminalLocalizationRequest( + val terminalLocalizations: List +) \ No newline at end of file diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/TerminalLocalizationResponse.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/TerminalLocalizationResponse.kt new file mode 100644 index 000000000..c9209c7e7 --- /dev/null +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/TerminalLocalizationResponse.kt @@ -0,0 +1,8 @@ +package co.nilin.opex.wallet.app.dto + +import co.nilin.opex.wallet.core.inout.TerminalLocalizationCommand + +data class TerminalLocalizationResponse( + val terminalUuid: String, + val terminalLocalizations: List +) \ No newline at end of file diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/TerminalLocalizationCommand.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/TerminalLocalizationCommand.kt new file mode 100644 index 000000000..683cda023 --- /dev/null +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/TerminalLocalizationCommand.kt @@ -0,0 +1,7 @@ +package co.nilin.opex.wallet.core.inout + +data class TerminalLocalizationCommand( + var id : Long?, + var description: String, + var language: String, +) diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/TerminalManager.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/TerminalManager.kt index 40012a209..2cd0aea0a 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/TerminalManager.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/TerminalManager.kt @@ -1,6 +1,7 @@ package co.nilin.opex.wallet.core.spi import co.nilin.opex.wallet.core.inout.TerminalCommand +import co.nilin.opex.wallet.core.inout.TerminalLocalizationCommand interface TerminalManager { @@ -9,4 +10,8 @@ interface TerminalManager { suspend fun delete(uuid: String) suspend fun fetchTerminal(): List? suspend fun fetchTerminal(uuid: String): TerminalCommand? + suspend fun saveTerminalLocalizations(terminalUuid : String , terminalLocalizations : List) : List + suspend fun fetchTerminalLocalizations(terminalUuid : String) : List + suspend fun deleteTerminalLocalizations(id : Long) + suspend fun updateTerminalLocalization(terminalLocalization : TerminalLocalizationCommand):TerminalLocalizationCommand } \ No newline at end of file diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/GatewayTerminalRepository.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/GatewayTerminalRepository.kt index be4f586db..39f7e11cb 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/GatewayTerminalRepository.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/GatewayTerminalRepository.kt @@ -1,6 +1,6 @@ package co.nilin.opex.wallet.ports.postgres.dao -import co.nilin.opex.wallet.ports.postgres.model.TerminalModel +import co.nilin.opex.wallet.ports.postgres.dto.TerminalView import co.nilin.opex.wallet.ports.postgres.model.GatewayTerminalModel import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository @@ -13,6 +13,23 @@ interface GatewayTerminalRepository : ReactiveCrudRepository - @Query("select t.* from gateway_terminal gt join terminal t on gt.terminal_id=t.id where gt.gateway_id=:gatewayId ") - fun findByGatewayId(gatewayId: Long): Flux? + @Query( + """ + SELECT t.id, + t.uuid, + t.owner, + t.identifier, + t.active, + t.type, + t.meta_data, + t.display_order, + tl.description + FROM gateway_terminal gt + JOIN terminal t ON gt.terminal_id=t.id + LEFT JOIN terminal_localization tl ON tl.terminal_id = t.id + AND tl.language = :lang + WHERE gt.gateway_id=:gatewayI + """ + ) + fun findByGatewayId(gatewayId: Long, lang: String? = null): Flux? } \ No newline at end of file diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/TerminalLocalizationsRepository.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/TerminalLocalizationsRepository.kt new file mode 100644 index 000000000..beac179ee --- /dev/null +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/TerminalLocalizationsRepository.kt @@ -0,0 +1,11 @@ +package co.nilin.opex.wallet.ports.postgres.dao + +import co.nilin.opex.wallet.ports.postgres.model.TerminalLocalizationModel +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository +import reactor.core.publisher.Flux + +@Repository +interface TerminalLocalizationsRepository : ReactiveCrudRepository { + suspend fun findByTerminalId(terminalId: Long): Flux +} \ No newline at end of file diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/TerminalRepository.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/TerminalRepository.kt index 4fe2971a2..ad0ca488c 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/TerminalRepository.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/TerminalRepository.kt @@ -1,6 +1,8 @@ package co.nilin.opex.wallet.ports.postgres.dao +import co.nilin.opex.wallet.ports.postgres.dto.TerminalView import co.nilin.opex.wallet.ports.postgres.model.TerminalModel +import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.stereotype.Repository import reactor.core.publisher.Flux @@ -9,8 +11,46 @@ import reactor.core.publisher.Mono @Repository interface TerminalRepository : ReactiveCrudRepository { fun findByIdentifier(identifier: String): Mono? - fun findByUuid(uuid: String): Mono? - fun findAllByOrderByDisplayOrder(): Flux + + @Query( + """ + SELECT t.id, + t.uuid, + t.owner, + t.identifier, + t.active, + t.type, + t.meta_data, + t.display_order, + tl.description + FROM terminal t + LEFT JOIN terminal_localization tl + ON tl.terminal_id = t.id + AND tl.language = :lang + WHERE t.uuid = :uuid; + """ + ) + fun findByUuid(uuid: String, lang: String? = null): Mono? + + @Query( + """ + SELECT t.id, + t.uuid, + t.owner, + t.identifier, + t.active, + t.type, + t.meta_data, + t.display_order, + tl.description + FROM terminal t + LEFT JOIN terminal_localization tl + ON tl.terminal_id = t.id + AND tl.language = :lang + order by t.display_order + """ + ) + fun findAllByOrderByDisplayOrder(lang: String?= null): Flux } \ No newline at end of file diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dto/TerminalView.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dto/TerminalView.kt new file mode 100644 index 000000000..5b7a18d7c --- /dev/null +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dto/TerminalView.kt @@ -0,0 +1,15 @@ +package co.nilin.opex.wallet.ports.postgres.dto + +import co.nilin.opex.wallet.core.inout.TransferMethod + +data class TerminalView( + var id: Long?, + val uuid: String, + val owner: String, + val identifier: String, + val active: Boolean, + val type: TransferMethod, + val metaData: String, + val displayOrder: Int?, + val description: String? +) diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/GatewayTerminalImpl.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/GatewayTerminalImpl.kt index 156ca460e..5fde477d8 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/GatewayTerminalImpl.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/GatewayTerminalImpl.kt @@ -1,13 +1,15 @@ package co.nilin.opex.wallet.ports.postgres.impl import co.nilin.opex.common.OpexError +import co.nilin.opex.common.data.UserLanguage +import co.nilin.opex.common.utils.LanguageUtils.getUserLanguage import co.nilin.opex.wallet.core.inout.TerminalCommand import co.nilin.opex.wallet.core.spi.GatewayTerminalManager -import co.nilin.opex.wallet.ports.postgres.dao.TerminalRepository import co.nilin.opex.wallet.ports.postgres.dao.GatewayTerminalRepository import co.nilin.opex.wallet.ports.postgres.dao.OffChainGatewayRepository +import co.nilin.opex.wallet.ports.postgres.dao.TerminalRepository import co.nilin.opex.wallet.ports.postgres.model.GatewayTerminalModel -import co.nilin.opex.wallet.ports.postgres.util.toDto +import co.nilin.opex.wallet.ports.postgres.util.toCommand import kotlinx.coroutines.reactor.awaitSingleOrNull import org.slf4j.LoggerFactory import org.springframework.stereotype.Component @@ -39,7 +41,10 @@ class GatewayTerminalImpl( override suspend fun getAssignedTerminalToGateway(gatewayUuid: String): List? { return gatewayRepository.findByGatewayUuid(gatewayUuid)?.awaitSingleOrNull()?.let { gateway -> - gatewayTerminalRepository.findByGatewayId(gateway.id!!)?.map { it.toDto() }?.collectList() + gatewayTerminalRepository.findByGatewayId( + gateway.id!!, + UserLanguage.safeValueOf(getUserLanguage().awaitSingleOrNull()).toString() + )?.map { it.toCommand() }?.collectList() ?.awaitSingleOrNull() } ?: throw OpexError.GatewayNotFount.exception() } diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/TerminalManagerImpl.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/TerminalManagerImpl.kt index 9a47fd687..9bc7b33d1 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/TerminalManagerImpl.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/TerminalManagerImpl.kt @@ -1,53 +1,151 @@ package co.nilin.opex.wallet.ports.postgres.impl import co.nilin.opex.common.OpexError +import co.nilin.opex.common.data.UserLanguage +import co.nilin.opex.common.utils.LanguageUtils.getDefaultUserLanguage +import co.nilin.opex.common.utils.LanguageUtils.getUserLanguage import co.nilin.opex.wallet.core.inout.TerminalCommand +import co.nilin.opex.wallet.core.inout.TerminalLocalizationCommand import co.nilin.opex.wallet.core.spi.TerminalManager +import co.nilin.opex.wallet.ports.postgres.dao.TerminalLocalizationsRepository import co.nilin.opex.wallet.ports.postgres.dao.TerminalRepository +import co.nilin.opex.wallet.ports.postgres.model.TerminalLocalizationModel import co.nilin.opex.wallet.ports.postgres.model.TerminalModel -import co.nilin.opex.wallet.ports.postgres.util.toDto +import co.nilin.opex.wallet.ports.postgres.util.toCommand import co.nilin.opex.wallet.ports.postgres.util.toModel +import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull import org.springframework.stereotype.Component +import org.springframework.transaction.reactive.TransactionalOperator +import org.springframework.transaction.reactive.executeAndAwait @Component -class TerminalManagerImpl(private val terminalRepository: TerminalRepository) : TerminalManager { +class TerminalManagerImpl( + private val terminalRepository: TerminalRepository, + private val terminalLocalizationsRepository: TerminalLocalizationsRepository, + private val transactionalOperator: TransactionalOperator + +) : TerminalManager { override suspend fun save(terminalCommand: TerminalCommand): TerminalCommand? { - terminalRepository.findByIdentifier(terminalCommand.identifier)?.awaitSingleOrNull() + + terminalRepository.findByIdentifier(terminalCommand.identifier) + ?.awaitSingleOrNull() ?.let { throw OpexError.TerminalIsExist.exception() } - return _save(terminalCommand.toModel())?.toDto() + + val terminal = terminalRepository + .save(terminalCommand.toModel()) + .awaitSingleOrNull() + ?: return null + + val terminalId = terminal.id ?: return null + + terminalCommand.description + ?.takeIf { it.isNotBlank() } + ?.let { description -> + terminalLocalizationsRepository.save( + TerminalLocalizationModel( + terminalId = terminalId, + description = description, + language = getDefaultUserLanguage() + ) + ).awaitSingleOrNull() + } + + return terminalCommand.apply { uuid = terminal.uuid } } override suspend fun update(terminalCommand: TerminalCommand): TerminalCommand? { loadTerminal(terminalCommand.uuid!!)?.let { - return _save(terminalCommand.toModel().apply { id = it.id })?.toDto() - } ?: throw OpexError.TerminalIsExist.exception() + val terminal = terminalRepository + .save(terminalCommand.toModel().apply { id = it.id }) + .awaitSingleOrNull() + ?: return null + return terminalRepository.findByUuid(terminal.uuid!!, getDefaultUserLanguage()) + ?.awaitSingleOrNull() + ?.toCommand() + } ?: throw OpexError.TerminalNotFound.exception() } override suspend fun delete(uuid: String) { loadTerminal(uuid)?.let { - terminalRepository.deleteById(it.id!!)?.awaitSingleOrNull() + terminalRepository.deleteById(it.id!!).awaitSingleOrNull() } ?: throw OpexError.TerminalNotFound.exception() } override suspend fun fetchTerminal(): List? { - return terminalRepository.findAllByOrderByDisplayOrder().map { it.toDto() }?.collectList()?.awaitSingleOrNull() + return terminalRepository.findAllByOrderByDisplayOrder( + UserLanguage.safeValueOf(getUserLanguage().awaitSingleOrNull()).toString() + ) + .map { it.toCommand() }.collectList().awaitSingleOrNull() } override suspend fun fetchTerminal(uuid: String): TerminalCommand? { - return loadTerminal(uuid!!)?.let { - it.toDto() - } ?: throw OpexError.TerminalIsExist.exception() + return terminalRepository.findByUuid( + uuid, + UserLanguage.safeValueOf(getUserLanguage().awaitSingleOrNull()).toString() + )?.awaitSingleOrNull() + ?.toCommand() } + override suspend fun saveTerminalLocalizations( + terminalUuid: String, + terminalLocalizations: List + ): List { + + return transactionalOperator.executeAndAwait { - private suspend fun _save(terminalModel: TerminalModel): TerminalModel? { - return terminalRepository.save(terminalModel)?.awaitSingleOrNull() + val terminal = loadTerminal(terminalUuid) + ?: throw OpexError.TerminalNotFound.exception() + terminalLocalizations.forEach { t -> + terminalLocalizationsRepository.save( + TerminalLocalizationModel( + terminalId = terminal.id!!, + description = t.description, + language = UserLanguage.safeValueOf(t.language).toString() + ) + ).awaitSingle() + } + + terminalLocalizationsRepository.findByTerminalId(terminal.id!!) + .map { it.toCommand() } + .collectList() + .awaitSingleOrNull() + ?: emptyList() + } ?: emptyList() + } + + override suspend fun fetchTerminalLocalizations(terminalUuid: String): List { + val terminal = loadTerminal(terminalUuid) + ?: throw OpexError.TerminalNotFound.exception() + return terminalLocalizationsRepository.findByTerminalId(terminal.id!!) + .map { it.toCommand() } + .collectList() + .awaitSingleOrNull() + ?: emptyList() + } + + override suspend fun deleteTerminalLocalizations(id: Long) { + terminalLocalizationsRepository.deleteById(id).awaitSingleOrNull() } private suspend fun loadTerminal(uuid: String): TerminalModel? { - return terminalRepository.findByUuid(uuid)?.awaitSingleOrNull() + return terminalRepository.findByUuid( + uuid, + UserLanguage.safeValueOf(getUserLanguage().awaitSingleOrNull()).toString() + )?.awaitSingleOrNull() + ?.toModel() + + } + override suspend fun updateTerminalLocalization(terminalLocalization: TerminalLocalizationCommand): TerminalLocalizationCommand { + if (terminalLocalization.id != null) { + val localizationModel = + terminalLocalizationsRepository.findById(terminalLocalization.id!!).awaitSingleOrNull() + ?: throw OpexError.TerminalLocalizationNotFound.exception() + localizationModel.apply { description = terminalLocalization.description } + return terminalLocalizationsRepository.save(localizationModel).awaitSingle().toCommand() + } + throw OpexError.TerminalLocalizationNotFound.exception() } } \ No newline at end of file diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/TerminalLocalizationModel.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/TerminalLocalizationModel.kt new file mode 100644 index 000000000..f6f2a0291 --- /dev/null +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/TerminalLocalizationModel.kt @@ -0,0 +1,13 @@ +package co.nilin.opex.wallet.ports.postgres.model + +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Table + +@Table("terminal_localization") +data class TerminalLocalizationModel( + @Id + var id: Long? = null, + var terminalId: Long, + var description: String, + var language: String, +) \ No newline at end of file diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/TerminalModel.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/TerminalModel.kt index 4437d5507..9f6887995 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/TerminalModel.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/TerminalModel.kt @@ -15,6 +15,5 @@ data class TerminalModel( var active: Boolean? = true, var type: TransferMethod, var metaData: String, - var description : String?, var displayOrder: Int? = null, ) \ No newline at end of file diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/util/Convertor.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/util/Convertor.kt index 836d13c3c..5c77cbd6b 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/util/Convertor.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/util/Convertor.kt @@ -2,6 +2,7 @@ package co.nilin.opex.wallet.ports.postgres.util import co.nilin.opex.wallet.core.inout.* import co.nilin.opex.wallet.core.model.TotalAssetsSnapshot +import co.nilin.opex.wallet.ports.postgres.dto.TerminalView import co.nilin.opex.wallet.ports.postgres.model.* import java.time.ZoneId import java.util.* @@ -143,7 +144,7 @@ fun TerminalCommand.toModel(): TerminalModel { null, uuid, owner, - identifier, active, type, metaData, description, displayOrder + identifier, active, type, metaData, displayOrder ) } @@ -151,10 +152,35 @@ fun TerminalModel.toDto(): TerminalCommand { return TerminalCommand( uuid!!, owner, + identifier, active, type, metaData, null, displayOrder + ) +} + +fun TerminalView.toModel(): TerminalModel { + return TerminalModel( + id, + uuid, + owner, + identifier, active, type, metaData, displayOrder + ) +} + +fun TerminalView.toCommand(): TerminalCommand { + return TerminalCommand( + uuid, + owner, identifier, active, type, metaData, description, displayOrder ) } +fun TerminalLocalizationModel.toCommand(): TerminalLocalizationCommand { + return TerminalLocalizationCommand( + id, + description, + language + ) +} + fun CurrencyModel.toCurrencyData(): CurrencyData { return CurrencyData( symbol, diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/db/migration/V8__add_terminal_localizations_table.sql b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/db/migration/V8__add_terminal_localizations_table.sql new file mode 100644 index 000000000..31bf9c3d4 --- /dev/null +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/db/migration/V8__add_terminal_localizations_table.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS terminal_localization +( + id SERIAL PRIMARY KEY, + terminal_id BIGINT NOT NULL REFERENCES terminal (id) ON DELETE CASCADE, + description TEXT NOT NULL, + language VARCHAR(10) NOT NULL, + UNIQUE (terminal_id, language) +); + +ALTER TABLE terminal + DROP COLUMN description; \ No newline at end of file