Skip to content

Commit

Permalink
Clean up deposit withdraw services (#466)
Browse files Browse the repository at this point in the history
* Simplified deposit services

* Clean up withdraw services
  • Loading branch information
Marchosiax authored Sep 17, 2024
1 parent 6890993 commit 528b234
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 190 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package co.nilin.opex.wallet.app.controller

import co.nilin.opex.common.OpexError
import co.nilin.opex.wallet.app.dto.DepositHistoryRequest
import co.nilin.opex.wallet.app.dto.DepositResponse
import co.nilin.opex.wallet.app.dto.ManualTransferRequest
import co.nilin.opex.wallet.app.dto.TransactionRequest
import co.nilin.opex.wallet.app.service.TransferService
import co.nilin.opex.wallet.core.inout.Deposits
import co.nilin.opex.wallet.core.inout.Deposit
import co.nilin.opex.wallet.core.inout.TransferResult
import co.nilin.opex.wallet.core.spi.DepositPersister
import io.swagger.annotations.ApiResponse
Expand All @@ -25,28 +25,37 @@ class DepositController(
private val transferService: TransferService
) {

@PostMapping("/{uuid}/history")
@PostMapping("/history")
suspend fun getDepositTransactionsForUser(
@PathVariable("uuid") uuid: String,
@RequestBody request: TransactionRequest,
@RequestBody request: DepositHistoryRequest,
@CurrentSecurityContext securityContext: SecurityContext
): Deposits {
if (securityContext.authentication.name != uuid)
throw OpexError.Forbidden.exception()

): List<DepositResponse> {
return depositPersister.findDepositHistory(
uuid,
request.coin,
securityContext.authentication.name,
request.currency,
request.startTime?.let {
LocalDateTime.ofInstant(Instant.ofEpochMilli(request.startTime), ZoneId.systemDefault())
},
request.endTime?.let {
LocalDateTime.ofInstant(Instant.ofEpochMilli(request.endTime), ZoneId.systemDefault())
},
request.limit!!,
request.offset!!,
request.limit,
request.offset,
request.ascendingByTime
)
).map {
DepositResponse(
it.id!!,
it.ownerUuid,
it.currency,
it.amount,
it.network,
it.note,
it.transactionRef,
it.status,
it.depositType,
it.createDate
)
}
}


Expand All @@ -69,8 +78,11 @@ class DepositController(
@CurrentSecurityContext securityContext: SecurityContext
): TransferResult {
return transferService.depositManually(
symbol, receiverUuid,
securityContext.authentication.name, amount, request
symbol,
receiverUuid,
securityContext.authentication.name,
amount,
request
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package co.nilin.opex.wallet.app.controller
import co.nilin.opex.common.OpexError
import co.nilin.opex.wallet.app.dto.AdminSearchWithdrawRequest
import co.nilin.opex.wallet.core.inout.*
import co.nilin.opex.wallet.core.model.Withdraw
import co.nilin.opex.wallet.core.service.WithdrawService
import io.swagger.annotations.ApiResponse
import io.swagger.annotations.Example
import io.swagger.annotations.ExampleProperty
import org.springframework.web.bind.annotation.*
import java.math.BigDecimal

Expand All @@ -20,12 +16,12 @@ class WithdrawAdminController(private val withdrawService: WithdrawService) {
return withdrawService.findWithdraw(id) ?: throw OpexError.WithdrawNotFound.exception()
}

@GetMapping
@PostMapping("/search")
suspend fun search(
@RequestParam offset: Int,
@RequestParam size: Int,
@RequestBody body: AdminSearchWithdrawRequest
): PagingWithdrawResponse {
): List<WithdrawResponse> {
return withdrawService.findByCriteria(
body.uuid,
body.currency,
Expand All @@ -43,7 +39,7 @@ class WithdrawAdminController(private val withdrawService: WithdrawService) {
@RequestParam destTransactionRef: String,
@RequestParam(required = false) destNote: String?,
@RequestParam(required = false) destAmount: BigDecimal?
): WithdrawResult {
): WithdrawActionResult {
return withdrawService.acceptWithdraw(
WithdrawAcceptCommand(
withdrawId,
Expand All @@ -55,15 +51,15 @@ class WithdrawAdminController(private val withdrawService: WithdrawService) {
}

@PostMapping("/{withdrawId}/process")
suspend fun processWithdraw(@PathVariable withdrawId: Long): WithdrawResult {
suspend fun processWithdraw(@PathVariable withdrawId: Long): WithdrawActionResult {
return withdrawService.processWithdraw(withdrawId)
}

@PostMapping("/{withdrawId}/reject")
suspend fun rejectWithdraw(
@PathVariable withdrawId: Long,
@RequestParam reason: String
): WithdrawResult {
): WithdrawActionResult {
return withdrawService.rejectWithdraw(WithdrawRejectCommand(withdrawId, reason))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package co.nilin.opex.wallet.app.controller
import co.nilin.opex.common.OpexError
import co.nilin.opex.wallet.app.dto.RequestWithdrawBody
import co.nilin.opex.wallet.app.dto.SearchWithdrawRequest
import co.nilin.opex.wallet.app.dto.TransactionRequest
import co.nilin.opex.wallet.app.dto.WithdrawHistoryResponse
import co.nilin.opex.wallet.app.dto.WithdrawHistoryRequest
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.inout.WithdrawActionResult
import co.nilin.opex.wallet.core.service.WithdrawService
import org.springframework.security.core.annotation.CurrentSecurityContext
import org.springframework.security.core.context.SecurityContext
import org.springframework.web.bind.annotation.*
import java.security.Principal
import java.time.Instant
Expand Down Expand Up @@ -36,7 +37,7 @@ class WithdrawController(private val withdrawService: WithdrawService) {
}

@PostMapping
suspend fun requestWithdraw(principal: Principal, @RequestBody request: RequestWithdrawBody): WithdrawResult {
suspend fun requestWithdraw(principal: Principal, @RequestBody request: RequestWithdrawBody): WithdrawActionResult {
return withdrawService.requestWithdraw(
with(request) {
WithdrawCommand(
Expand All @@ -58,14 +59,14 @@ class WithdrawController(private val withdrawService: WithdrawService) {
withdrawService.cancelWithdraw(principal.name, withdrawId)
}

@PostMapping("/history/{uuid}")
@PostMapping("/history")
suspend fun getWithdrawTransactionsForUser(
@PathVariable uuid: String,
@RequestBody request: TransactionRequest
): List<WithdrawHistoryResponse> {
@CurrentSecurityContext securityContext: SecurityContext,
@RequestBody request: WithdrawHistoryRequest,
): List<WithdrawResponse> {
return withdrawService.findWithdrawHistory(
uuid,
request.coin,
securityContext.authentication.name,
request.currency,
request.startTime?.let {
LocalDateTime.ofInstant(Instant.ofEpochMilli(request.startTime), ZoneId.systemDefault())
},
Expand All @@ -75,24 +76,6 @@ class WithdrawController(private val withdrawService: WithdrawService) {
request.limit!!,
request.offset!!,
request.ascendingByTime
).map {
WithdrawHistoryResponse(
it.withdrawId,
it.ownerUuid,
it.amount,
it.currency,
it.appliedFee,
it.destAmount,
it.destSymbol,
it.destAddress,
it.destNetwork,
it.destNote,
it.destTransactionRef,
it.statusReason,
it.status,
it.createDate.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(),
it.acceptDate?.atZone(ZoneId.systemDefault())?.toInstant()?.toEpochMilli(),
)
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package co.nilin.opex.wallet.app.dto

data class DepositHistoryRequest(
val currency: String? = null,
val startTime: Long? = null,
val endTime: Long? = null,
val limit: Int = 10,
val offset: Int = 0,
val ascendingByTime: Boolean = false
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package co.nilin.opex.wallet.app.dto

import co.nilin.opex.wallet.core.model.DepositStatus
import co.nilin.opex.wallet.core.model.DepositType
import java.math.BigDecimal
import java.time.LocalDateTime
import java.util.Date

data class DepositResponse(
val id: Long,
val uuid: String,
val currency: String,
val amount: BigDecimal,
val network: String?,
val note: String?,
val transactionRef: String?,
val status: DepositStatus,
val type: DepositType,
val createDate: Date?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package co.nilin.opex.wallet.app.dto

data class WithdrawHistoryRequest(
val currency: String?,
val startTime: Long? = null,
val endTime: Long? = null,
val limit: Int? = 10,
val offset: Int? = 0,
val ascendingByTime: Boolean = false
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import co.nilin.opex.wallet.app.service.otc.GraphService
import co.nilin.opex.wallet.core.inout.Deposit
import co.nilin.opex.wallet.core.inout.TransferCommand
import co.nilin.opex.wallet.core.inout.TransferResult
import co.nilin.opex.wallet.core.model.Amount
import co.nilin.opex.wallet.core.model.TransferCategory
import co.nilin.opex.wallet.core.model.WalletType
import co.nilin.opex.wallet.core.model.*
import co.nilin.opex.wallet.core.model.otc.Rate
import co.nilin.opex.wallet.core.model.otc.ReservedTransfer
import co.nilin.opex.wallet.core.spi.*
Expand Down Expand Up @@ -95,8 +93,8 @@ class TransferService(
amount,
note = description,
transactionRef = transferRef,
status = "Done",
depositType = "On-chain",
status = DepositStatus.DONE,
depositType = DepositType.ON_CHAIN,
network = chain
)
)
Expand Down Expand Up @@ -325,8 +323,8 @@ class TransferService(
amount,
note = request.description,
transactionRef = request.ref,
status = "Done",
depositType = "System",
status = DepositStatus.DONE,
depositType = DepositType.SYSTEM,
)
)
return tx
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package co.nilin.opex.wallet.core.inout

import co.nilin.opex.wallet.core.model.DepositStatus
import co.nilin.opex.wallet.core.model.DepositType
import java.math.BigDecimal
import java.time.LocalDateTime
import java.util.*

data class Deposit(
var ownerUuid: String,
var depositUuid: String,
var currency: String,
var amount: BigDecimal,
var acceptedFee: BigDecimal?=null,
var appliedFee: BigDecimal?=null,
var sourceSymbol: String?=null,
var network: String?=null,
var sourceAddress: String?=null,
var transactionRef: String?=null,
var note: String?=null,
var status: String?=null,
var depositType:String?=null,
var createDate: Date?=Date(),
var ownerUuid: String,
var depositUuid: String,
var currency: String,
var amount: BigDecimal,
var acceptedFee: BigDecimal? = null,
var appliedFee: BigDecimal? = null,
var sourceSymbol: String? = null,
var network: String? = null,
var sourceAddress: String? = null,
var transactionRef: String? = null,
var note: String? = null,
var status: DepositStatus,
var depositType: DepositType,
var createDate: Date = Date(),
val id:Long? = null,
)



data class Deposits(var deposits: List<Deposit>)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package co.nilin.opex.wallet.core.inout

import co.nilin.opex.wallet.core.model.WithdrawStatus

class WithdrawResult(val withdrawId: Long, val status: WithdrawStatus) {
class WithdrawActionResult(val withdrawId: Long, val status: WithdrawStatus) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import java.util.*

class WithdrawResponse(
val withdrawId: Long,
val ownerUuid: String,
val requestDate: Date,
val finalizedDate: Date?,
val requestTransaction: String,
val finalizedTransaction: String?,
val appliedFee: BigDecimal?,
val amount: BigDecimal?,
val uuid: String,
val amount: BigDecimal,
val currency: String,
val appliedFee: BigDecimal,
val destAmount: BigDecimal?,
val destSymbol: String?,
val destAddress: String?,
Expand All @@ -22,6 +19,6 @@ class WithdrawResponse(
var destTransactionRef: String?,
val statusReason: String?,
val status: WithdrawStatus,
val createDate: LocalDateTime = LocalDateTime.now(),
val acceptDate: LocalDateTime? = null
val createDate: LocalDateTime,
val acceptDate: LocalDateTime?
)
Loading

0 comments on commit 528b234

Please sign in to comment.