-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from NTF-marketplace/refactor/transaction
Refactor/transaction
- Loading branch information
Showing
18 changed files
with
306 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ package com.api.admin.controller.dto | |
|
||
data class WithdrawERC721Request( | ||
val nftId: Long, | ||
val accountLogId: Long, | ||
) |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/api/admin/domain/transferFailLog/TransferFailLog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.api.admin.domain.transferFailLog | ||
|
||
import com.api.admin.enums.TransferType | ||
import org.springframework.data.annotation.Id | ||
import org.springframework.data.relational.core.mapping.Table | ||
import java.sql.Timestamp | ||
|
||
@Table("transfer_fail_log") | ||
data class TransferFailLog( | ||
@Id val id: Long? = null, | ||
val wallet: String, | ||
val timestamp: Long? = System.currentTimeMillis(), | ||
val transactionHash: String?, | ||
val errorMessage: String, | ||
val transferType: TransferType, | ||
) |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/api/admin/domain/transferFailLog/TransferFailLogRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.api.admin.domain.transferFailLog | ||
|
||
import org.springframework.data.repository.reactive.ReactiveCrudRepository | ||
|
||
interface TransferFailLogRepository: ReactiveCrudRepository<TransferFailLog,Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,7 @@ enum class TokenType { | |
MATIC, ETH | ||
} | ||
|
||
|
||
enum class TransactionStatusType { | ||
SUCCESS, FAILURE | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/api/admin/rabbitMQ/event/dto/AdminTransferDetailResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.api.admin.rabbitMQ.event.dto | ||
|
||
import com.api.admin.enums.TransferType | ||
import java.math.BigDecimal | ||
|
||
data class AdminTransferDetailResponse( | ||
val nftId: Long?, | ||
val transferType: TransferType, | ||
val balance: BigDecimal?, | ||
) |
39 changes: 32 additions & 7 deletions
39
src/main/kotlin/com/api/admin/rabbitMQ/event/dto/AdminTransferResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
package com.api.admin.rabbitMQ.event.dto | ||
|
||
import com.api.admin.domain.transfer.Transfer | ||
import com.api.admin.domain.transferFailLog.TransferFailLog | ||
import com.api.admin.enums.AccountType | ||
import com.api.admin.enums.ChainType | ||
import com.api.admin.enums.TransactionStatusType | ||
import com.api.admin.enums.TransferType | ||
import com.api.admin.rabbitMQ.event.dto.AdminTransferResponse.Companion.toResponse | ||
import java.math.BigDecimal | ||
|
||
|
||
data class AdminTransferResponse( | ||
val id: Long, | ||
val walletAddress: String, | ||
val nftId: Long?, | ||
val timestamp: Long, | ||
val accountLogId: Long, | ||
val accountType: AccountType, | ||
val transferType: TransferType, | ||
val balance: BigDecimal?, | ||
val chainType: ChainType, | ||
) | ||
val transactionStatusType: TransactionStatusType, | ||
val adminTransferDetailResponse: AdminTransferDetailResponse? | ||
) { | ||
companion object { | ||
fun Transfer.toResponse(accountId: Long) = AdminTransferResponse( | ||
accountLogId = accountId, | ||
accountType = this.accountType, | ||
transferType = this.transferType, | ||
transactionStatusType = TransactionStatusType.SUCCESS, | ||
adminTransferDetailResponse = AdminTransferDetailResponse( | ||
nftId = this.nftId, | ||
transferType =this.transferType, | ||
balance = this.balance | ||
) | ||
) | ||
|
||
fun TransferFailLog.toResponse(accountId: Long,accountType: AccountType) = AdminTransferResponse( | ||
accountLogId = accountId, | ||
accountType = accountType, | ||
transferType = this.transferType, | ||
transactionStatusType = TransactionStatusType.FAILURE, | ||
adminTransferDetailResponse = null | ||
|
||
) | ||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/com/api/admin/service/TransferFailService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.api.admin.service | ||
|
||
import com.api.admin.domain.transferFailLog.TransferFailLog | ||
import com.api.admin.domain.transferFailLog.TransferFailLogRepository | ||
import com.api.admin.enums.AccountType | ||
import com.api.admin.enums.TransferType | ||
import com.api.admin.rabbitMQ.event.dto.AdminTransferCreatedEvent | ||
import com.api.admin.rabbitMQ.event.dto.AdminTransferResponse.Companion.toResponse | ||
import org.springframework.context.ApplicationEventPublisher | ||
import org.springframework.stereotype.Service | ||
import reactor.core.publisher.Mono | ||
|
||
@Service | ||
class TransferFailService( | ||
private val transferFailLogRepository: TransferFailLogRepository, | ||
private val eventPublisher: ApplicationEventPublisher, | ||
) { | ||
|
||
fun save(accountId: Long, | ||
address: String, | ||
transactionHash: String?, | ||
message: String, | ||
transferType: TransferType, | ||
accountType: AccountType | ||
): Mono<Void> { | ||
return transferFailLogRepository.save( | ||
TransferFailLog( | ||
wallet = address, | ||
transactionHash = transactionHash, | ||
errorMessage = message, | ||
transferType = transferType | ||
) | ||
).doOnSuccess { | ||
eventPublisher.publishEvent(AdminTransferCreatedEvent(this, it.toResponse(accountId,accountType))) | ||
}.then() | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.