Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ServiceInstance>): 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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>?
@RequestParam("status", required = false) status: List<String>?,
@RequestParam offset: Int,
@RequestParam size: Int
): List<WithdrawResponse> {
return withdrawService
.findByCriteria(
Expand All @@ -42,7 +44,9 @@ class AdminController(private val withdrawService: WithdrawService) {
destTxRef,
destAddress,
status?.isEmpty() ?: true,
status ?: listOf("")
status ?: listOf(""),
offset,
size
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,7 +47,9 @@ class WithdrawController(private val withdrawService: WithdrawService) {
destTxRef,
destAddress,
status?.isEmpty() ?: true,
status ?: listOf("")
status ?: listOf(""),
null,
null
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ class WithdrawService(
destTxRef: String?,
destAddress: String?,
noStatus: Boolean,
status: List<String>?
status: List<String>?,
offset: Int?,
size: Int?
): List<WithdrawResponse> {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ interface WithdrawPersister {
status: List<String>?
): List<WithdrawResponse>

suspend fun findByCriteria(
ownerUuid: String?,
withdrawId: String?,
currency: String?,
destTxRef: String?,
destAddress: String?,
noStatus: Boolean,
status: List<String>?,
offset: Int,
size:Int
): List<WithdrawResponse>

suspend fun persist(withdraw: Withdraw): Withdraw

suspend fun findById(withdrawId: String): Withdraw?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,32 @@ import java.time.LocalDateTime

@Repository
interface WithdrawRepository : ReactiveCrudRepository<WithdrawModel, String> {

@Query("select * from withdraws where wallet = :wallet")
fun findByWallet(
@Param("wallet") wallet: Long
): Flow<WithdrawModel>
fun findByWallet(@Param("wallet") wallet: Long): Flow<WithdrawModel>

@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<WithdrawModel>
fun findByOwner(@Param("owner") owner: Long): Flow<WithdrawModel>

@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?,
Expand All @@ -47,6 +48,33 @@ interface WithdrawRepository : ReactiveCrudRepository<WithdrawModel, String> {
@Param("status") status: List<String>?
): Flow<WithdrawModel>

@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<String>?,
offset: Int,
size: Int
): Flow<WithdrawModel>

@Query("select * from withdraws where wallet = :wallet and transaction_id = :tx_id")
fun findByWalletAndTransactionId(
@Param("wallet") wallet: Long,
Expand Down
Loading