diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/CurrencyLocalizationRequest.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/CurrencyLocalizationRequest.kt deleted file mode 100644 index ce10ffd9f..000000000 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/CurrencyLocalizationRequest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package co.nilin.opex.api.core.inout - - -data class CurrencyLocalizationRequest( - val currencyLocalizations: List -) \ No newline at end of file diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/TerminalLocalizationCommand.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/TerminalLocalizationCommand.kt index 091e1ddf2..eaba72509 100644 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/TerminalLocalizationCommand.kt +++ b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/TerminalLocalizationCommand.kt @@ -2,6 +2,7 @@ package co.nilin.opex.api.core.inout data class TerminalLocalizationCommand( var id : Long?, - var description: String, + var description: String?=null, + var owner: String?=null, var language: String, ) diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/TerminalLocalizationRequest.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/TerminalLocalizationRequest.kt deleted file mode 100644 index a18474392..000000000 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/inout/TerminalLocalizationRequest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package co.nilin.opex.api.core.inout - - -data class TerminalLocalizationRequest( - val terminalLocalizations: List -) \ No newline at end of file diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/WalletProxy.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/WalletProxy.kt index f24a83d18..9bbc50efa 100644 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/WalletProxy.kt +++ b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/WalletProxy.kt @@ -215,26 +215,16 @@ interface WalletProxy { suspend fun saveCurrencyLocalizations( token: String, currency: String, - request: CurrencyLocalizationRequest + currencyLocalizations: List ): CurrencyLocalizationResponse - suspend fun updateCurrencyLocalization( - token: String, - request: CurrencyLocalizationCommand - ): CurrencyLocalizationCommand - suspend fun deleteCurrencyLocalization(token: String, id: Long) suspend fun getTerminalLocalizations(token: String, terminalUuid: String): TerminalLocalizationResponse suspend fun saveTerminalLocalizations( token: String, terminalUuid: String, - request: TerminalLocalizationRequest + terminalLocalizations: List ): TerminalLocalizationResponse - suspend fun updateTerminalLocalization( - token: String, - request: TerminalLocalizationCommand - ): TerminalLocalizationCommand - suspend fun deleteTerminalLocalization(token: String, id: Long) } \ No newline at end of file diff --git a/api/api-ports/api-opex-rest/src/main/kotlin/co/nilin/opex/api/ports/opex/controller/LocalizationAdminController.kt b/api/api-ports/api-opex-rest/src/main/kotlin/co/nilin/opex/api/ports/opex/controller/LocalizationAdminController.kt index ba00e6e36..c582cb7fb 100644 --- a/api/api-ports/api-opex-rest/src/main/kotlin/co/nilin/opex/api/ports/opex/controller/LocalizationAdminController.kt +++ b/api/api-ports/api-opex-rest/src/main/kotlin/co/nilin/opex/api/ports/opex/controller/LocalizationAdminController.kt @@ -1,6 +1,9 @@ package co.nilin.opex.api.ports.opex.controller -import co.nilin.opex.api.core.inout.* +import co.nilin.opex.api.core.inout.CurrencyLocalizationCommand +import co.nilin.opex.api.core.inout.CurrencyLocalizationResponse +import co.nilin.opex.api.core.inout.TerminalLocalizationCommand +import co.nilin.opex.api.core.inout.TerminalLocalizationResponse import co.nilin.opex.api.core.spi.WalletProxy import co.nilin.opex.api.ports.opex.util.jwtAuthentication import co.nilin.opex.api.ports.opex.util.tokenValue @@ -25,23 +28,15 @@ class LocalizationAdminController( suspend fun saveCurrencyLocalizations( @CurrentSecurityContext securityContext: SecurityContext, @PathVariable("currency") currency: String, - @RequestBody request: CurrencyLocalizationRequest + @RequestBody currencyLocalizations: List ): CurrencyLocalizationResponse { return walletProxy.saveCurrencyLocalizations( securityContext.jwtAuthentication().tokenValue(), currency, - request + currencyLocalizations ) } - @PutMapping("/currency/localization") - suspend fun updateCurrencyLocalization( - @CurrentSecurityContext securityContext: SecurityContext, - @RequestBody request: CurrencyLocalizationCommand - ): CurrencyLocalizationCommand { - return walletProxy.updateCurrencyLocalization(securityContext.jwtAuthentication().tokenValue(), request) - } - @DeleteMapping("/currency/localization/{id}") suspend fun deleteCurrencyLocalization( @CurrentSecurityContext securityContext: SecurityContext, @@ -62,23 +57,15 @@ class LocalizationAdminController( suspend fun saveTerminalLocalizations( @CurrentSecurityContext securityContext: SecurityContext, @PathVariable("terminalUuid") terminalUuid: String, - @RequestBody request: TerminalLocalizationRequest + @RequestBody terminalLocalizations: List ): TerminalLocalizationResponse { return walletProxy.saveTerminalLocalizations( securityContext.jwtAuthentication().tokenValue(), terminalUuid, - request + terminalLocalizations ) } - @PutMapping("/terminal/localization") - suspend fun updateTerminalLocalization( - @CurrentSecurityContext securityContext: SecurityContext, - @RequestBody request: TerminalLocalizationCommand - ): TerminalLocalizationCommand { - return walletProxy.updateTerminalLocalization(securityContext.jwtAuthentication().tokenValue(), request) - } - @DeleteMapping("/terminal/localization/{id}") suspend fun deleteTerminalLocalization( @CurrentSecurityContext securityContext: SecurityContext, diff --git a/api/api-ports/api-proxy-rest/src/main/kotlin/co/nilin/opex/api/ports/proxy/impl/WalletProxyImpl.kt b/api/api-ports/api-proxy-rest/src/main/kotlin/co/nilin/opex/api/ports/proxy/impl/WalletProxyImpl.kt index 9d58ea104..dc68dabd2 100644 --- a/api/api-ports/api-proxy-rest/src/main/kotlin/co/nilin/opex/api/ports/proxy/impl/WalletProxyImpl.kt +++ b/api/api-ports/api-proxy-rest/src/main/kotlin/co/nilin/opex/api/ports/proxy/impl/WalletProxyImpl.kt @@ -819,34 +819,19 @@ class WalletProxyImpl(@Qualifier("generalWebClient") private val webClient: WebC override suspend fun saveCurrencyLocalizations( token: String, currency: String, - request: CurrencyLocalizationRequest + currencyLocalizations: List ): CurrencyLocalizationResponse { return webClient.post() .uri("$baseUrl/currency/${currency}/localization") .accept(MediaType.APPLICATION_JSON) .header(HttpHeaders.AUTHORIZATION, "Bearer $token") - .body(Mono.just(request)) + .body(Mono.just(currencyLocalizations)) .retrieve() .onStatus({ t -> t.isError }, { it.createException() }) .bodyToMono() .awaitFirstOrElse { throw OpexError.BadRequest.exception() } } - override suspend fun updateCurrencyLocalization( - token: String, - request: CurrencyLocalizationCommand - ): CurrencyLocalizationCommand { - return webClient.put() - .uri("$baseUrl/currency/localization") - .accept(MediaType.APPLICATION_JSON) - .header(HttpHeaders.AUTHORIZATION, "Bearer $token") - .body(Mono.just(request)) - .retrieve() - .onStatus({ t -> t.isError }, { it.createException() }) - .bodyToMono() - .awaitFirstOrElse { throw OpexError.BadRequest.exception() } - } - override suspend fun deleteCurrencyLocalization(token: String, id: Long) { webClient.delete() .uri("$baseUrl/currency/localization/${id}") @@ -876,34 +861,19 @@ class WalletProxyImpl(@Qualifier("generalWebClient") private val webClient: WebC override suspend fun saveTerminalLocalizations( token: String, terminalUuid: String, - request: TerminalLocalizationRequest + terminalLocalizations: List ): TerminalLocalizationResponse { return webClient.post() .uri("$baseUrl/admin/deposit/terminal/${terminalUuid}/localization") .accept(MediaType.APPLICATION_JSON) .header(HttpHeaders.AUTHORIZATION, "Bearer $token") - .body(Mono.just(request)) + .body(Mono.just(terminalLocalizations)) .retrieve() .onStatus({ t -> t.isError }, { it.createException() }) .bodyToMono() .awaitFirstOrElse { throw OpexError.BadRequest.exception() } } - override suspend fun updateTerminalLocalization( - token: String, - request: TerminalLocalizationCommand - ): TerminalLocalizationCommand { - return webClient.put() - .uri("$baseUrl/admin/deposit/terminal/localization") - .accept(MediaType.APPLICATION_JSON) - .header(HttpHeaders.AUTHORIZATION, "Bearer $token") - .body(Mono.just(request)) - .retrieve() - .onStatus({ t -> t.isError }, { it.createException() }) - .bodyToMono() - .awaitFirstOrElse { throw OpexError.BadRequest.exception() } - } - override suspend fun deleteTerminalLocalization(token: String, id: Long) { webClient.delete() .uri("$baseUrl/admin/deposit/terminal/localization/${id}") diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/CurrencyController.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/CurrencyController.kt index 667cdefaf..42fc2e0b1 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/CurrencyController.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/CurrencyController.kt @@ -163,17 +163,12 @@ class CurrencyController( @PostMapping("/{currency}/localization") suspend fun saveCurrencyLocalizations( @PathVariable("currency") currency: String, - @RequestBody request: CurrencyLocalizationRequest + @RequestBody currencyLocalizations: List ): CurrencyLocalizationResponse { - val localizations = currencyService.saveCurrencyLocalizations(currency, request.currencyLocalizations) + val localizations = currencyService.saveCurrencyLocalizations(currency, currencyLocalizations) return CurrencyLocalizationResponse(currency, localizations) } - @PutMapping("/localization") - suspend fun updateCurrencyLocalization(@RequestBody request: CurrencyLocalizationCommand): CurrencyLocalizationCommand { - return currencyService.updateCurrencyLocalization(request) - } - @DeleteMapping("/localization/{id}") suspend fun deleteCurrencyLocalization(@PathVariable("id") id: Long) { currencyService.deleteCurrencyLocalization(id) 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 64ae66137..4284252ac 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,7 +2,6 @@ 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 @@ -145,9 +144,9 @@ class DepositAdminController( @PostMapping("/terminal/{uuid}/localization") suspend fun saveTerminalLocalization( @PathVariable("uuid") terminalUuid: String, - @RequestBody body: TerminalLocalizationRequest + @RequestBody terminalLocalizations: List ): TerminalLocalizationResponse { - val terminalLocalizations = terminalManager.saveTerminalLocalizations(terminalUuid, body.terminalLocalizations) + val terminalLocalizations = terminalManager.saveTerminalLocalizations(terminalUuid, terminalLocalizations) return TerminalLocalizationResponse(terminalUuid, terminalLocalizations) } @@ -165,12 +164,4 @@ class DepositAdminController( ) { 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 deleted file mode 100644 index c4622eee5..000000000 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/dto/TerminalLocalizationRequest.kt +++ /dev/null @@ -1,7 +0,0 @@ -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/service/CurrencyServiceV2.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/CurrencyServiceV2.kt index 5174f45f9..da2b2e364 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/CurrencyServiceV2.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/CurrencyServiceV2.kt @@ -167,10 +167,6 @@ class CurrencyServiceV2( return currencyServiceManager.saveCurrencyLocalizations(currency, request); } - suspend fun updateCurrencyLocalization(request: CurrencyLocalizationCommand): CurrencyLocalizationCommand { - return currencyServiceManager.updateCurrencyLocalization(request) - } - suspend fun deleteCurrencyLocalization(id: Long) { currencyServiceManager.deleteCurrencyLocalization(id) } diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/TerminalCommand.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/TerminalCommand.kt index f6760e689..3d801a3f8 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/TerminalCommand.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/inout/TerminalCommand.kt @@ -2,12 +2,12 @@ package co.nilin.opex.wallet.core.inout data class TerminalCommand( var uuid: String?, - var owner: String, + var owner: String? = null, var identifier: String, var active: Boolean? = true, var type: TransferMethod, var metaData: String, - var description : String?, + var description : String? = null, var displayOrder: Int? = null, ) 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 index 683cda023..1c9c98e5c 100644 --- 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 @@ -2,6 +2,7 @@ package co.nilin.opex.wallet.core.inout data class TerminalLocalizationCommand( var id : Long?, - var description: String, + var description: String?=null, + var owner: String?=null, var language: String, ) diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/CurrencyServiceManager.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/CurrencyServiceManager.kt index c5db39e9a..3d6c877fa 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/CurrencyServiceManager.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/CurrencyServiceManager.kt @@ -21,7 +21,6 @@ interface CurrencyServiceManager { localizations: List ): List - suspend fun updateCurrencyLocalization(request: CurrencyLocalizationCommand): CurrencyLocalizationCommand suspend fun deleteCurrencyLocalization(id: Long) } \ No newline at end of file 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 2cd0aea0a..8168c1c12 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 @@ -13,5 +13,4 @@ interface TerminalManager { 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/CurrencyLocalizationsRepository.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/CurrencyLocalizationsRepository.kt index 034b1ef5b..d18fdef35 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/CurrencyLocalizationsRepository.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/CurrencyLocalizationsRepository.kt @@ -1,11 +1,39 @@ package co.nilin.opex.wallet.ports.postgres.dao import co.nilin.opex.wallet.ports.postgres.model.CurrencyLocalizationModel +import org.springframework.data.r2dbc.repository.Modifying +import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.stereotype.Repository import reactor.core.publisher.Flux +import reactor.core.publisher.Mono @Repository interface CurrencyLocalizationsRepository : ReactiveCrudRepository { suspend fun findByCurrency(currency: String): Flux + + @Modifying + @Query( + """ + INSERT INTO currency_localization (currency, name, title, alias, description, short_description, language) + VALUES (:currency, :name, :title, :alias, :description, :shortDescription, :language) + ON CONFLICT (currency, language) + DO UPDATE SET + name = :name, + title = :title, + alias = :alias, + description = :description, + short_description = :shortDescription +""" + ) + fun upsert( + currency: String, + name: String?, + title: String?, + alias: String?, + description: String?, + shortDescription: String?, + language: String + ): Mono + } \ 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 index beac179ee..c9fadf52a 100644 --- 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 @@ -1,11 +1,32 @@ package co.nilin.opex.wallet.ports.postgres.dao import co.nilin.opex.wallet.ports.postgres.model.TerminalLocalizationModel +import org.springframework.data.r2dbc.repository.Modifying +import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.stereotype.Repository import reactor.core.publisher.Flux +import reactor.core.publisher.Mono @Repository interface TerminalLocalizationsRepository : ReactiveCrudRepository { suspend fun findByTerminalId(terminalId: Long): Flux + + @Modifying + @Query( + """ + INSERT INTO terminal_localization (terminal_id, description, owner, language) + VALUES (:terminalId, :description, :owner, :language) + ON CONFLICT (terminal_id, language) + DO UPDATE SET + description = :description, + owner = :owner +""" + ) + fun upsert( + terminalId: Long, + description: String?, + owner: String?, + language: String + ): Mono } \ 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 ad0ca488c..351abeae1 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 @@ -16,7 +16,7 @@ interface TerminalRepository : ReactiveCrudRepository { """ SELECT t.id, t.uuid, - t.owner, + tl.owner, t.identifier, t.active, t.type, @@ -36,7 +36,7 @@ interface TerminalRepository : ReactiveCrudRepository { """ SELECT t.id, t.uuid, - t.owner, + tl.owner, t.identifier, t.active, t.type, 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 index 5b7a18d7c..ef9748c13 100644 --- 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 @@ -5,7 +5,7 @@ import co.nilin.opex.wallet.core.inout.TransferMethod data class TerminalView( var id: Long?, val uuid: String, - val owner: String, + val owner: String?, val identifier: String, val active: Boolean, val type: TransferMethod, diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/CurrencyServiceImplV2.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/CurrencyServiceImplV2.kt index f353de635..1dce8aeda 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/CurrencyServiceImplV2.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/CurrencyServiceImplV2.kt @@ -108,8 +108,15 @@ class CurrencyServiceImplV2( ?: throw OpexError.CurrencyNotFound.exception() localizations.forEach { c -> - currencyLocalizationsRepository.save( - CurrencyLocalizationModel( + if (listOf( + c.name, + c.title, + c.alias, + c.description, + c.shortDescription + ).any { !it.isNullOrBlank() } + ) + currencyLocalizationsRepository.upsert( currency = symbol, name = c.name, title = c.title, @@ -117,8 +124,7 @@ class CurrencyServiceImplV2( description = c.description, shortDescription = c.shortDescription, language = UserLanguage.safeValueOf(c.language).toString() - ) - ).awaitSingle() + ).awaitSingleOrNull() } currencyLocalizationsRepository.findByCurrency(symbol).map { it.toCommand() }.collectList() @@ -126,23 +132,6 @@ class CurrencyServiceImplV2( } ?: throw OpexError.BadRequest.exception("Failed to save currency localizations") } - override suspend fun updateCurrencyLocalization(request: CurrencyLocalizationCommand): CurrencyLocalizationCommand { - if (request.id != null) { - val localizationModel = - currencyLocalizationsRepository.findById(request.id!!).awaitSingleOrNull() - ?: throw OpexError.CurrencyLocalizationNotFound.exception() - localizationModel.apply { - name = request.name - title = request.title - alias = request.alias - description = request.description - shortDescription = request.shortDescription - } - return currencyLocalizationsRepository.save(localizationModel).awaitSingle().toCommand() - } - throw OpexError.CurrencyLocalizationNotFound.exception() - } - override suspend fun deleteCurrencyLocalization(id: Long) { currencyLocalizationsRepository.deleteById(id).awaitSingleOrNull() } 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 2869ae50a..a29338f7f 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 @@ -40,17 +40,17 @@ class TerminalManagerImpl( val terminalId = terminal.id ?: return@executeAndAwait null - terminalCommand.description - ?.takeIf { it.isNotBlank() } - ?.let { description -> - terminalLocalizationsRepository.save( - TerminalLocalizationModel( - terminalId = terminalId, - description = description, - language = getDefaultUserLanguage() - ) - ).awaitSingleOrNull() - } + + if (!terminalCommand.description.isNullOrBlank() || !terminalCommand.owner.isNullOrBlank()) { + terminalLocalizationsRepository.save( + TerminalLocalizationModel( + terminalId = terminalId, + description = terminalCommand.description, + owner = terminalCommand.owner, + language = getDefaultUserLanguage() + ) + ).awaitSingleOrNull() + } terminalCommand.apply { uuid = terminal.uuid } } @@ -100,13 +100,13 @@ class TerminalManagerImpl( ?: throw OpexError.TerminalNotFound.exception() terminalLocalizations.forEach { t -> - terminalLocalizationsRepository.save( - TerminalLocalizationModel( + if (!t.description.isNullOrBlank() || !t.owner.isNullOrBlank()) + terminalLocalizationsRepository.upsert( terminalId = terminal.id!!, description = t.description, + owner = t.owner, language = UserLanguage.safeValueOf(t.language).toString() - ) - ).awaitSingle() + ).awaitSingleOrNull() } terminalLocalizationsRepository.findByTerminalId(terminal.id!!) @@ -139,15 +139,4 @@ class TerminalManagerImpl( ?.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 index f6f2a0291..bc11d2b81 100644 --- 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 @@ -8,6 +8,7 @@ data class TerminalLocalizationModel( @Id var id: Long? = null, var terminalId: Long, - var description: String, + var description: String?=null, + var owner: String?=null, 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 9f6887995..a5a756ed8 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 @@ -10,7 +10,6 @@ data class TerminalModel( @Id var id: Long?, var uuid: String? = UUID.randomUUID().toString(), - var owner: String, var identifier: String, var active: Boolean? = true, var type: TransferMethod, 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 9151b2ec8..daa8f8cc9 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 @@ -186,24 +186,14 @@ fun TerminalCommand.toModel(): TerminalModel { return TerminalModel( null, uuid, - owner, identifier, active, type, metaData, displayOrder ) } -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 ) } @@ -220,6 +210,7 @@ fun TerminalLocalizationModel.toCommand(): TerminalLocalizationCommand { return TerminalLocalizationCommand( id, description, + owner, language ) } diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/db/migration/V10__update_terminal_localizations_table.sql b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/db/migration/V10__update_terminal_localizations_table.sql new file mode 100644 index 000000000..20cd65249 --- /dev/null +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/db/migration/V10__update_terminal_localizations_table.sql @@ -0,0 +1,12 @@ +ALTER TABLE terminal_localization + ADD COLUMN owner VARCHAR(255); + +UPDATE terminal_localization tl +SET owner = ( + SELECT t.owner + FROM terminal t + WHERE t.id = tl.terminal_id +); + +ALTER TABLE terminal + DROP COLUMN owner; \ No newline at end of file