Skip to content

Commit

Permalink
Merge pull request #24 from NTF-marketplace/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
min-96 authored Oct 18, 2024
2 parents 16bef4b + 2cb88a8 commit f0061d5
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/com/api/nft/config/KafkaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.springframework.kafka.core.ConsumerFactory
import org.springframework.kafka.core.DefaultKafkaConsumerFactory
import org.springframework.kafka.core.KafkaAdmin
import org.springframework.kafka.listener.CommonErrorHandler
import org.springframework.kafka.listener.ContainerProperties
import org.springframework.kafka.listener.MessageListenerContainer
import org.springframework.kafka.support.serializer.JsonDeserializer

Expand Down Expand Up @@ -48,6 +49,7 @@ class KafkaConfig {
val factory = ConcurrentKafkaListenerContainerFactory<String, Any>()
factory.consumerFactory = consumerFactory()
factory.setConcurrency(4)
factory.containerProperties.ackMode = ContainerProperties.AckMode.RECORD
factory.setCommonErrorHandler(
object : CommonErrorHandler {
override fun handleRemaining(
Expand Down
8 changes: 0 additions & 8 deletions src/main/kotlin/com/api/nft/controller/NftController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,4 @@ class NftController(
return nftService.getByWalletNft(wallet,chainType)

}
// collection을 구현할건데 1h / 7h /12h / 24h / 7d/ 30d
// Listing은 matched volume 이 높은순이여야돼



// aution은 현재 acution중인것


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.api.nft.domain.attribute

import org.springframework.data.repository.reactive.ReactiveCrudRepository
import reactor.core.publisher.Flux

interface AttributeRepository : ReactiveCrudRepository<Attribute,Long> {

fun findAllByNftId(nftId: Long): Flux<Attribute>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.api.nft.domain.metadata.repository

import com.api.nft.domain.metadata.Metadata
import org.springframework.data.repository.reactive.ReactiveCrudRepository
import reactor.core.publisher.Mono

interface MetadataRepository: ReactiveCrudRepository<Metadata,Long> {

fun findByNftId(nftId: Long) : Mono<Metadata>
}
1 change: 1 addition & 0 deletions src/main/kotlin/com/api/nft/event/dto/NftResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ data class NftResponse(
val tokenId: String,
val tokenAddress: String,
val chainType: ChainType,
val collectionName: String,
)
8 changes: 8 additions & 0 deletions src/main/kotlin/com/api/nft/properties/MarketApiProperties.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.api.nft.properties

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "market")
data class MarketApiProperties(
val uri: String
)
5 changes: 5 additions & 0 deletions src/main/kotlin/com/api/nft/service/api/AttributeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.api.nft.domain.attribute.AttributeRepository
import com.api.nft.service.external.dto.NftAttribute
import org.springframework.stereotype.Service
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

@Service
class AttributeService(
Expand All @@ -22,4 +23,8 @@ class AttributeService(
)
}
}

fun findByAttribute(nftId: Long): Flux<Attribute> {
return attributeRepository.findAllByNftId(nftId)
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/com/api/nft/service/api/MetadataService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class MetadataService(
animationUrl = metadata.animationUrl,
)
)
}

fun findByMetadata(nftId: Long): Mono<Metadata> {
return metadataRepository.findByNftId(nftId)
}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/com/api/nft/service/api/NftAuctionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ class NftAuctionService(
)
).then()
}

fun findByNftId(nftId: Long): Mono<NftAuction> {
return nftAuctionRepository.findByNftId(nftId)
}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/com/api/nft/service/api/NftListingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ class NftListingService(
)
}

fun findByNftId(nftId: Long): Mono<NftListing> {
return nftListingRepository.findByNftId(nftId)
}

}
45 changes: 45 additions & 0 deletions src/main/kotlin/com/api/nft/service/api/NftService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.api.nft.enums.ContractType
import com.api.nft.event.dto.NftCreatedEvent
import com.api.nft.event.dto.NftResponse
import com.api.nft.service.RedisService
import com.api.nft.service.dto.NftDetailResponse
import com.api.nft.service.external.MarketApiService
import com.api.nft.service.external.dto.NftAttribute
import com.api.nft.service.external.dto.NftData
import com.api.nft.service.external.dto.NftMetadata
Expand All @@ -27,8 +29,50 @@ class NftService(
private val transferService: TransferService,
private val moralisApiService: MoralisApiService,
private val redisService: RedisService,
private val marketApiService: MarketApiService,
private val nftListingService: NftListingService,
private val nftAuctionService: NftAuctionService,
) {

fun findByNftDetail1(nftId: Long): Mono<NftDetailResponse> {
return nftRepository.findById(nftId)
.flatMap { nft ->
val metadataMono = metadataService.findByMetadata(nftId)
val attributeMono = attributeService.findByAttribute(nftId).collectList()
val transferMono = transferService.findOrUpdateByNftId(nftId).collectList()
val listingMono = nftListingService.findByNftId(nftId)
val auctionMono = nftAuctionService.findByNftId(nftId)
.flatMap { auction ->
marketApiService.getOfferHistory(auction.id).collectList()
.map { offers -> auction to offers }
}.defaultIfEmpty(null to emptyList())

val ledgerMono = marketApiService.getLedgerHistory(nftId).collectList()

Mono.zip(metadataMono, attributeMono, transferMono, listingMono, auctionMono, ledgerMono)
.map { tuple ->
val metadata = tuple.t1
val attributes = tuple.t2
val transfers = tuple.t3
val listing = tuple.t4
val (auction, offers) = tuple.t5
val ledgers = tuple.t6

NftDetailResponse(
nft = nft,
metadata = metadata,
attributes = attributes,
transfers = transfers,
listing = listing,
auction = auction,
offers = offers,
ledgers = ledgers,
)
}
}
}


fun findAllById(ids: List<Long>): Flux<NftMetadataResponse> {
return nftRepository.findAllByNftJoinMetadata(ids)
.flatMap { nft ->
Expand Down Expand Up @@ -96,6 +140,7 @@ class NftService(
tokenId = this.tokenId,
tokenAddress = this.tokenAddress,
chainType = this.chainType,
collectionName = this.collectionName
)

fun getNftData(request: NftData, chainType: ChainType): Mono<Triple<NftData, NftMetadata, List<NftAttribute>?>> {
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/com/api/nft/service/dto/NftClientResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.api.nft.service.dto

import com.api.nft.enums.ChainType
import com.api.nft.enums.ContractType

data class NftClientResponse(
val id: Long,
val tokenId: String,
val tokenAddress: String,
val chainType: ChainType,
val contractType: ContractType,
val nftName: String,
val tokenHash: String,
)
20 changes: 20 additions & 0 deletions src/main/kotlin/com/api/nft/service/dto/NftDetailResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.api.nft.service.dto

import com.api.nft.domain.attribute.Attribute
import com.api.nft.domain.metadata.Metadata
import com.api.nft.domain.nft.Nft
import com.api.nft.domain.nft.NftAuction
import com.api.nft.domain.nft.NftListing
import com.api.nft.domain.trasfer.Transfer


data class NftDetailResponse(
val nft : Nft,
val metadata : Metadata,
val attributes : List<Attribute>,
val transfers : List<Transfer>,
val listing : NftListing?,
val auction : NftAuction?,
val offers: List<Any>?,
val ledgers: List<Any>?
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.api.nft.service
package com.api.nft.service.dto

import java.math.BigInteger

Expand Down
39 changes: 39 additions & 0 deletions src/main/kotlin/com/api/nft/service/external/MarketApiService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.api.nft.service.external

import com.api.nft.properties.MarketApiProperties
import org.springframework.stereotype.Service
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

@Service
class MarketApiService(
marketApiProperties: MarketApiProperties
) {
private val webClient = WebClient.builder()
.baseUrl(marketApiProperties.uri )
.build()

//TODO("")
fun getOfferHistory(nftId: Long): Flux<Any> {
return webClient.get()
.uri{
it.path("/v1/offer/history")
.queryParam("nftId", nftId)
it.build()
}
.retrieve()
.bodyToFlux(Any::class.java)
}
//TODO("")
fun getLedgerHistory(nftId: Long): Flux<Any> {
return webClient.get()
.uri{
it.path("/v1/orders/history")
.queryParam("nftId", nftId)
it.build()
}
.retrieve()
.bodyToFlux(Any::class.java)
}
}

0 comments on commit f0061d5

Please sign in to comment.