diff --git a/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/SecurityConfig.kt b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/SecurityConfig.kt index ec7fe45dc..332aca562 100644 --- a/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/SecurityConfig.kt +++ b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/SecurityConfig.kt @@ -22,6 +22,7 @@ class SecurityConfig(private val webClient: WebClient) { .authorizeExchange() .pathMatchers("/auth/**").hasRole("SCOPE_trust", "finance-admin") .pathMatchers("/system/**").hasRole("SCOPE_trust", "system-admin") + .pathMatchers("/actuator/health").permitAll() .anyExchange().authenticated() .and() .oauth2ResourceServer() diff --git a/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/WebClientConfig.kt b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/WebClientConfig.kt index c36afd50f..c018c01fb 100644 --- a/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/WebClientConfig.kt +++ b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/WebClientConfig.kt @@ -1,18 +1,24 @@ package co.nilin.opex.admin.app.config +import co.nilin.opex.utility.log.CustomLogger import org.springframework.cloud.client.ServiceInstance import org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalancer import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.http.client.reactive.ReactorClientHttpConnector import org.springframework.web.reactive.function.client.WebClient +import reactor.netty.http.client.HttpClient @Configuration class WebClientConfig { @Bean fun webClient(loadBalancerFactory: ReactiveLoadBalancer.Factory): WebClient { + val logger = CustomLogger(HttpClient::class.java) + val connector = HttpClient.create().doOnRequest { _, con -> con.addHandlerFirst(logger) } return WebClient.builder() + .clientConnector(ReactorClientHttpConnector(connector)) .filter(ReactorLoadBalancerExchangeFilterFunction(loadBalancerFactory, emptyList())) .build() } diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/AdminController.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/AdminController.kt index e9f563b50..9ebd4bf40 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/AdminController.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/AdminController.kt @@ -32,7 +32,9 @@ class AdminController(private val withdrawService: WithdrawService) { @RequestParam("currency", required = false) currency: String?, @RequestParam("dest_transaction_ref", required = false) destTxRef: String?, @RequestParam("dest_address", required = false) destAddress: String?, - @RequestParam("status", required = false) status: List? + @RequestParam("status", required = false) status: List?, + @RequestParam offset: Int, + @RequestParam size: Int ): List { return withdrawService .findByCriteria( @@ -42,7 +44,9 @@ class AdminController(private val withdrawService: WithdrawService) { destTxRef, destAddress, status?.isEmpty() ?: true, - status ?: listOf("") + status ?: listOf(""), + offset, + size ) } diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/WithdrawController.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/WithdrawController.kt index 20ad264ba..755066034 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/WithdrawController.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/controller/WithdrawController.kt @@ -2,7 +2,9 @@ package co.nilin.opex.wallet.app.controller import co.nilin.opex.wallet.app.dto.TransactionRequest import co.nilin.opex.wallet.app.dto.WithdrawHistoryResponse -import co.nilin.opex.wallet.core.inout.* +import co.nilin.opex.wallet.core.inout.WithdrawCommand +import co.nilin.opex.wallet.core.inout.WithdrawResponse +import co.nilin.opex.wallet.core.inout.WithdrawResult import co.nilin.opex.wallet.core.service.WithdrawService import io.swagger.annotations.ApiResponse import io.swagger.annotations.Example @@ -45,7 +47,9 @@ class WithdrawController(private val withdrawService: WithdrawService) { destTxRef, destAddress, status?.isEmpty() ?: true, - status ?: listOf("") + status ?: listOf(""), + null, + null ) } diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt index e17f25e65..09bbf6f55 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt @@ -178,10 +178,15 @@ class WithdrawService( destTxRef: String?, destAddress: String?, noStatus: Boolean, - status: List? + status: List?, + offset: Int?, + size: Int? ): List { - return withdrawPersister - .findByCriteria(ownerUuid, withdrawId, currency, destTxRef, destAddress, noStatus, status) + return if (offset == null || size == null) + withdrawPersister.findByCriteria(ownerUuid, withdrawId, currency, destTxRef, destAddress, noStatus, status) + else + withdrawPersister + .findByCriteria(ownerUuid, withdrawId, currency, destTxRef, destAddress, noStatus, status, offset, size) } suspend fun findWithdrawHistory( diff --git a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/WithdrawPersister.kt b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/WithdrawPersister.kt index 5de53a9eb..03d4d4e33 100644 --- a/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/WithdrawPersister.kt +++ b/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/spi/WithdrawPersister.kt @@ -16,6 +16,18 @@ interface WithdrawPersister { status: List? ): List + suspend fun findByCriteria( + ownerUuid: String?, + withdrawId: String?, + currency: String?, + destTxRef: String?, + destAddress: String?, + noStatus: Boolean, + status: List?, + offset: Int, + size:Int + ): List + suspend fun persist(withdraw: Withdraw): Withdraw suspend fun findById(withdrawId: String): Withdraw? diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/WithdrawRepository.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/WithdrawRepository.kt index f176717c8..f021e9258 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/WithdrawRepository.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/WithdrawRepository.kt @@ -11,31 +11,32 @@ import java.time.LocalDateTime @Repository interface WithdrawRepository : ReactiveCrudRepository { + @Query("select * from withdraws where wallet = :wallet") - fun findByWallet( - @Param("wallet") wallet: Long - ): Flow + fun findByWallet(@Param("wallet") wallet: Long): Flow @Query( - "select * from withdraws wth " + - " join wallet wm on wm.id = wth.wallet " + - " where wm.owner = :owner" + """ + select * from withdraws wth + join wallet wm on wm.id = wth.wallet + where wm.owner = :owner + """ ) - fun findByOwner( - @Param("owner") owner: Long - ): Flow + fun findByOwner(@Param("owner") owner: Long): Flow @Query( - "select * from withdraws wth " + - " join wallet wm on wm.id = wth.wallet " + - " join wallet_owner wo on wm.owner = wo.id " + - " where ( :owner is null or wo.uuid = :owner) " + - " and (:withdraw_id is null or wth.id = :withdraw_id )" + - " and (:dest_transaction_ref is null or wth.dest_transaction_ref = :dest_transaction_ref)" + - " and (:dest_address is null or wth.dest_address = :dest_address)" + - " and (:no_status IS TRUE or wth.status in (:status))" + - " and (:currency is null or wm.currency in (:currency))" + - " order by wth.id asc" + """ + select * from withdraws wth + join wallet wm on wm.id = wth.wallet + join wallet_owner wo on wm.owner = wo.id + where ( :owner is null or wo.uuid = :owner) + and (:withdraw_id is null or wth.id = :withdraw_id ) + and (:dest_transaction_ref is null or wth.dest_transaction_ref = :dest_transaction_ref) + and (:dest_address is null or wth.dest_address = :dest_address) + and (:no_status IS TRUE or wth.status in (:status)) + and (:currency is null or wm.currency in (:currency)) + order by wth.id asc + """ ) fun findByCriteria( @Param("owner") ownerUuid: String?, @@ -47,6 +48,33 @@ interface WithdrawRepository : ReactiveCrudRepository { @Param("status") status: List? ): Flow + @Query( + """ + select * from withdraws wth + join wallet wm on wm.id = wth.wallet + join wallet_owner wo on wm.owner = wo.id + where ( :owner is null or wo.uuid = :owner) + and (:withdraw_id is null or wth.id = :withdraw_id ) + and (:dest_transaction_ref is null or wth.dest_transaction_ref = :dest_transaction_ref) + and (:dest_address is null or wth.dest_address = :dest_address) + and (:no_status IS TRUE or wth.status in (:status)) + and (:currency is null or wm.currency in (:currency)) + order by wth.id asc + offset :offset limit :size + """ + ) + fun findByCriteria( + @Param("owner") ownerUuid: String?, + @Param("withdraw_id") withdrawId: Long?, + @Param("currency") currency: String?, + @Param("dest_transaction_ref") destTxRef: String?, + @Param("dest_address") destAddress: String?, + @Param("no_status") noStatus: Boolean, + @Param("status") status: List?, + offset: Int, + size: Int + ): Flow + @Query("select * from withdraws where wallet = :wallet and transaction_id = :tx_id") fun findByWalletAndTransactionId( @Param("wallet") wallet: Long, diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WithdrawPersisterImpl.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WithdrawPersisterImpl.kt index 6633d7aa0..8c89c2031 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WithdrawPersisterImpl.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WithdrawPersisterImpl.kt @@ -21,6 +21,33 @@ class WithdrawPersisterImpl( private val transactionRepository: TransactionRepository ) : WithdrawPersister { + override suspend fun findByCriteria( + ownerUuid: String?, + withdrawId: String?, + currency: String?, + destTxRef: String?, + destAddress: String?, + noStatus: Boolean, + status: List?, + offset: Int, + size: Int + ): List { + return withdrawRepository + .findByCriteria( + ownerUuid, + withdrawId?.toLong(), + currency, + destTxRef, + destAddress, + noStatus, + status, + offset, + size + ) + .map { it.asWithdrawResponse() } + .toList() + } + override suspend fun findByCriteria( ownerUuid: String?, withdrawId: String?, @@ -31,42 +58,16 @@ class WithdrawPersisterImpl( status: List? ): List { return withdrawRepository - .findByCriteria(ownerUuid, withdrawId?.toLong(), currency, destTxRef, destAddress, noStatus, status) - .map { wm -> - val reqTx = transactionRepository.findById(wm.requestTransaction.toLong()).awaitFirst() - val finalTx = if (wm.finalizedTransaction == null) - null - else - transactionRepository.findById(wm.finalizedTransaction.toLong()).awaitFirstOrNull() - WithdrawResponse( - wm.id!!, - wm.ownerUuid, - Date.from( - reqTx.txDate.atZone(ZoneId.systemDefault()).toInstant() - ), - if (finalTx == null) - null - else - Date.from( - finalTx.txDate.atZone(ZoneId.systemDefault()).toInstant() - ), - reqTx.id.toString(), - finalTx?.id.toString(), - wm.acceptedFee, - wm.appliedFee, - wm.amount, - wm.destAmount, - wm.destCurrency, - wm.destAddress, - wm.destNetwork, - wm.destNote, - wm.destTransactionRef, - wm.statusReason, - wm.status, - wm.createDate, - wm.acceptDate - ) - } + .findByCriteria( + ownerUuid, + withdrawId?.toLong(), + currency, + destTxRef, + destAddress, + noStatus, + status + ) + .map { it.asWithdrawResponse() } .toList() } @@ -93,52 +94,13 @@ class WithdrawPersisterImpl( withdraw.acceptDate ) ).awaitFirst() - return Withdraw( - wm.id, - withdraw.ownerUuid, - withdraw.wallet, - withdraw.amount, - withdraw.requestTransaction, - withdraw.finalizedTransaction, - withdraw.acceptedFee, - withdraw.appliedFee, - withdraw.destAmount, - withdraw.destCurrency, - withdraw.destAddress, - withdraw.destNetwork, - withdraw.destNote, - withdraw.destTransactionRef, - withdraw.statusReason, - withdraw.status, - withdraw.createDate, - withdraw.acceptDate - ) + + return wm.asWithdraw() } override suspend fun findById(withdrawId: String): Withdraw? { return withdrawRepository.findById(withdrawId) - .map { withdraw -> - Withdraw( - withdraw.id, - withdraw.ownerUuid, - withdraw.wallet, - withdraw.amount, - withdraw.requestTransaction, - withdraw.finalizedTransaction, - withdraw.acceptedFee, - withdraw.appliedFee, - withdraw.destAmount, - withdraw.destCurrency, - withdraw.destAddress, - withdraw.destNetwork, - withdraw.destNote, - withdraw.destTransactionRef, - withdraw.statusReason, - withdraw.status, - withdraw.createDate, - withdraw.acceptDate - ) - } + .map { it.asWithdraw() } .awaitFirstOrNull() } @@ -154,28 +116,58 @@ class WithdrawPersisterImpl( withdrawRepository.findWithdrawHistory(uuid, startTime, endTime, limit) else withdrawRepository.findWithdrawHistory(uuid, coin, startTime, endTime, limit) + return withdraws.map { it.asWithdraw() }.toList() + } - return withdraws.map { withdraw -> - Withdraw( - withdraw.id, - withdraw.ownerUuid, - withdraw.wallet, - withdraw.amount, - withdraw.requestTransaction, - withdraw.finalizedTransaction, - withdraw.acceptedFee, - withdraw.appliedFee, - withdraw.destAmount, - withdraw.destCurrency, - withdraw.destAddress, - withdraw.destNetwork, - withdraw.destNote, - withdraw.destTransactionRef, - withdraw.statusReason, - withdraw.status, - withdraw.createDate, - withdraw.acceptDate - ) - }.toList() + private suspend fun WithdrawModel.asWithdrawResponse(): WithdrawResponse { + val reqTx = transactionRepository.findById(requestTransaction.toLong()).awaitFirst() + val finalTx = if (finalizedTransaction == null) + null + else + transactionRepository.findById(finalizedTransaction.toLong()).awaitFirstOrNull() + return WithdrawResponse( + id!!, + ownerUuid, + Date.from(reqTx.txDate.atZone(ZoneId.systemDefault()).toInstant()), + if (finalTx == null) null else Date.from(finalTx.txDate.atZone(ZoneId.systemDefault()).toInstant()), + reqTx.id.toString(), + finalTx?.id.toString(), + acceptedFee, + appliedFee, + amount, + destAmount, + destCurrency, + destAddress, + destNetwork, + destNote, + destTransactionRef, + statusReason, + status, + createDate, + acceptDate + ) + } + + private fun WithdrawModel.asWithdraw(): Withdraw { + return Withdraw( + id, + ownerUuid, + wallet, + amount, + requestTransaction, + finalizedTransaction, + acceptedFee, + appliedFee, + destAmount, + destCurrency, + destAddress, + destNetwork, + destNote, + destTransactionRef, + statusReason, + status, + createDate, + acceptDate + ) } } \ No newline at end of file