Skip to content

Commit

Permalink
Merge pull request #75 from OpenFuturePlatform/SA-91_Extend_API_of_Ke…
Browse files Browse the repository at this point in the history
…y_management_service

Order wallet unique check
  • Loading branch information
Elaman Nazarkulov authored May 10, 2023
2 parents c141fa0 + 9a266f3 commit d9abd7b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.openfuture.state.blockchain
package io.openfuture.state.blockchain.ethereum

import io.openfuture.state.blockchain.Blockchain
import io.openfuture.state.blockchain.dto.UnifiedBlock
import io.openfuture.state.blockchain.dto.UnifiedTransaction
import io.openfuture.state.domain.CurrencyCode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.openfuture.state.blockchain
package io.openfuture.state.blockchain.ethereum

import io.openfuture.state.blockchain.Blockchain
import io.openfuture.state.blockchain.dto.UnifiedBlock
import io.openfuture.state.blockchain.dto.UnifiedTransaction
import io.openfuture.state.domain.CurrencyCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ import reactor.core.publisher.Mono
interface OrderRepository : ReactiveMongoRepository<Order, String>{
suspend fun findByOrderKey(orderKey: String): Mono<Order>
suspend fun existsByOrderKey(orderKey: String): Mono<Boolean>
suspend fun existsByOrderKeyAndApplicationId(orderKey: String, applicationId: String): Mono<Boolean>
suspend fun findAllByApplicationId(applicationId: String): Flux<Order>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ interface WalletRepository : ReactiveMongoRepository<Wallet, String> {

fun findByIdentity(identity: WalletIdentity): Mono<Wallet>

fun existsByIdentity(identity: WalletIdentity): Mono<Boolean>

fun findFirstByIdentityAddress(address: String): Mono<Wallet>

fun findAllByUserData_Order_OrderKey(orderKey: String): Flux<Wallet>

fun findFirstByUserData_Order_OrderKey(orderKey: String): Mono<Wallet>

fun findByIdentityBlockchainAndIdentityAddress(blockchain: String, address: String): Mono<Wallet>

fun deleteByIdentity(identity: WalletIdentity)

fun findAllByApplicationId(applicationId: String): Flux<Wallet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DefaultWalletService(
request.metadata.amount,
request.metadata.productCurrency
)
val existOrder = orderRepository.existsByOrderKey(request.metadata.orderKey).awaitSingle()
val existOrder = orderRepository.existsByOrderKeyAndApplicationId(request.metadata.orderKey, request.applicationId).awaitSingle()
if (!existOrder) {
orderRepository.save(order).awaitSingle()
}
Expand All @@ -96,7 +96,9 @@ class DefaultWalletService(
userData = userData,
walletType = WalletType.FOR_ORDER
)
savedWallets.add(walletRepository.save(wallet).awaitSingle())
val existWallet = walletRepository.existsByIdentity(walletIdentity).awaitSingle()
if (!existWallet)
savedWallets.add(walletRepository.save(wallet).awaitSingle())
}
val wallets = savedWallets.map { WalletCreateResponse(it.identity.blockchain, it.identity.address, it.userData.rate) }
return PlaceOrderResponse(
Expand Down

0 comments on commit d9abd7b

Please sign in to comment.