-
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.
- Loading branch information
Showing
9 changed files
with
129 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.api.nft.domain.nft | ||
|
||
import com.api.nft.enums.StatusType | ||
import com.api.nft.enums.TokenType | ||
import org.springframework.data.relational.core.mapping.Table | ||
import java.math.BigDecimal | ||
|
||
@Table("nft_auction") | ||
data class NftAuction( | ||
val id: Long? = null, | ||
val startingPrice: BigDecimal, | ||
val tokenType: TokenType, | ||
val nftId: Long, | ||
val statusType: StatusType, | ||
val createdDate: Long, | ||
val endDate: Long, | ||
|
||
) { | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/api/nft/domain/nft/repository/NftAuctionRepository.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,17 @@ | ||
package com.api.nft.domain.nft.repository | ||
|
||
import com.api.nft.domain.nft.NftAuction | ||
import com.api.nft.enums.StatusType | ||
import org.springframework.data.r2dbc.repository.Query | ||
import org.springframework.data.r2dbc.repository.R2dbcRepository | ||
import reactor.core.publisher.Mono | ||
|
||
interface NftAuctionRepository : R2dbcRepository<NftAuction,Long> { | ||
fun findByNftId(nftId: Long) : Mono<NftAuction> | ||
|
||
@Query("UPDATE nft_auction SET status_type = :statusType WHERE nft_id = :nftId") | ||
fun updateAuction(nftId: Long, statusType: StatusType): Mono<Void> | ||
|
||
fun deleteByNftId(nftId: Long): Mono<Void> | ||
|
||
} |
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
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/com/api/nft/service/api/NftAuctionService.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,48 @@ | ||
package com.api.nft.service.api | ||
|
||
import com.api.nft.domain.nft.NftAuction | ||
import com.api.nft.domain.nft.repository.NftAuctionRepository | ||
import com.api.nft.enums.StatusType | ||
import com.api.nft.service.dto.AuctionResponse | ||
import org.springframework.stereotype.Service | ||
import reactor.core.publisher.Mono | ||
|
||
@Service | ||
class NftAuctionService( | ||
private val nftAuctionRepository: NftAuctionRepository, | ||
) { | ||
|
||
fun update(newAuction: AuctionResponse): Mono<Void> { | ||
return when (newAuction.statusType) { | ||
StatusType.RESERVATION -> { | ||
save(newAuction) | ||
} | ||
StatusType.ACTIVED -> { | ||
nftAuctionRepository.findByNftId(newAuction.nftId) | ||
.flatMap { | ||
nftAuctionRepository.updateAuction(nftId = newAuction.nftId, statusType = StatusType.AUCTION) | ||
} | ||
} | ||
StatusType.RESERVATION_CANCEL, StatusType.CANCEL, StatusType.EXPIRED -> { | ||
nftAuctionRepository.findByNftId(newAuction.nftId) | ||
.flatMap { nftAuction -> | ||
nftAuctionRepository.deleteByNftId(nftAuction.nftId) | ||
} | ||
|
||
} | ||
else -> Mono.empty() | ||
} | ||
} | ||
fun save(auction: AuctionResponse) : Mono<Void> { | ||
return nftAuctionRepository.save( | ||
NftAuction( | ||
nftId = auction.nftId, | ||
startingPrice = auction.startingPrice, | ||
tokenType = auction.tokenType, | ||
statusType = auction.statusType, | ||
createdDate = auction.createdDateTime, | ||
endDate = auction.endDateTime, | ||
) | ||
).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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/api/nft/service/dto/AuctionResponse.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.nft.service.dto | ||
|
||
import com.api.nft.enums.StatusType | ||
import com.api.nft.enums.TokenType | ||
import java.math.BigDecimal | ||
|
||
data class AuctionResponse( | ||
val id : Long, | ||
val nftId : Long, | ||
val address: String, | ||
val createdDateTime: Long, | ||
val endDateTime: Long, | ||
val statusType: StatusType, | ||
val startingPrice: BigDecimal, | ||
val tokenType: TokenType | ||
) |
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