Skip to content

Commit

Permalink
feat: sale topic
Browse files Browse the repository at this point in the history
  • Loading branch information
min-96 committed Sep 4, 2024
1 parent 4b42384 commit 27ffe01
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 54 deletions.
5 changes: 3 additions & 2 deletions src/main/kotlin/com/api/nft/config/KafkaConfig.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.api.nft.config

import org.apache.kafka.clients.admin.AdminClientConfig
import org.apache.kafka.clients.admin.NewTopic
import org.apache.kafka.clients.consumer.ConsumerConfig
import org.apache.kafka.common.serialization.StringDeserializer
import org.slf4j.LoggerFactory
Expand All @@ -9,11 +10,11 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.kafka.annotation.EnableKafka
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory
import org.springframework.kafka.config.TopicBuilder
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 All @@ -33,7 +34,7 @@ class KafkaConfig {
val props =
mapOf(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers,
ConsumerConfig.GROUP_ID_CONFIG to "wallet-group",
ConsumerConfig.GROUP_ID_CONFIG to "nft-group",
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java.name,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to JsonDeserializer::class.java.name,
JsonDeserializer.TRUSTED_PACKAGES to "*",
Expand Down
8 changes: 0 additions & 8 deletions src/main/kotlin/com/api/nft/config/RabbitConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,4 @@ class RabbitConfig {

@Bean
fun nftExchange() = createFanoutExchange("nftExchange")


@Bean
fun listingExchange() = createFanoutExchange("listingExchange")


@Bean
fun auctionExchange() = createFanoutExchange("auctionExchange")
}
11 changes: 10 additions & 1 deletion src/main/kotlin/com/api/nft/kafka/KafkaConsumer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.api.nft.kafka

import com.api.nft.enums.OrderType
import com.api.nft.kafka.dto.SaleResponse
import com.api.nft.service.api.NftAuctionService
import com.api.nft.service.api.NftListingService
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.kafka.annotation.KafkaListener
import org.springframework.messaging.Message
Expand All @@ -9,6 +12,8 @@ import org.springframework.stereotype.Service
@Service
class KafkaConsumer(
private val objectMapper: ObjectMapper,
private val nftListingService: NftListingService,
private val nftAuctionService: NftAuctionService
) {
@KafkaListener(topics = ["sale-topic"],
groupId = "nft-group",
Expand All @@ -19,8 +24,12 @@ class KafkaConsumer(

if (payload is LinkedHashMap<*, *>) {
val saleStatusRequest = objectMapper.convertValue(payload, SaleResponse::class.java)

println("saleStatusRequest : " + saleStatusRequest)
when(saleStatusRequest.orderType){
OrderType.LISTING -> nftListingService.update(saleStatusRequest).subscribe()
OrderType.AUCTION -> nftAuctionService.update(saleStatusRequest).subscribe()
}

// orderService.updateOrderStatus(ledgerStatusRequest).subscribe()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/api/nft/kafka/dto/SaleResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class SaleResponse(
val createdDateTime: Long,
val endDateTime: Long,
val statusType: StatusType,
val startingPrice: BigDecimal,
val price: BigDecimal,
val chainType: ChainType,
val orderType: OrderType
)
Expand Down
36 changes: 0 additions & 36 deletions src/main/kotlin/com/api/nft/rabbitMQ/RabbitMQReceiver.kt

This file was deleted.

7 changes: 4 additions & 3 deletions src/main/kotlin/com/api/nft/service/api/NftAuctionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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.kafka.dto.SaleResponse
import com.api.nft.service.dto.AuctionResponse
import org.springframework.stereotype.Service
import reactor.core.publisher.Mono
Expand All @@ -12,7 +13,7 @@ class NftAuctionService(
private val nftAuctionRepository: NftAuctionRepository,
) {

fun update(newAuction: AuctionResponse): Mono<Void> {
fun update(newAuction: SaleResponse): Mono<Void> {
return when (newAuction.statusType) {
StatusType.RESERVATION -> {
save(newAuction)
Expand All @@ -33,12 +34,12 @@ class NftAuctionService(
else -> Mono.empty()
}
}
fun save(auction: AuctionResponse) : Mono<Void> {
fun save(auction: SaleResponse) : Mono<Void> {
return nftAuctionRepository.save(
NftAuction(
id = auction.id,
nftId = auction.nftId,
startingPrice = auction.startingPrice,
startingPrice = auction.price,
chainType = auction.chainType,
statusType = auction.statusType,
createdDate = auction.createdDateTime,
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/api/nft/service/api/NftListingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.api.nft.service.api
import com.api.nft.domain.nft.NftListing
import com.api.nft.domain.nft.repository.NftListingRepository
import com.api.nft.enums.StatusType
import com.api.nft.kafka.dto.SaleResponse
import com.api.nft.service.RedisService
import com.api.nft.service.dto.ListingResponse
import org.springframework.stereotype.Service
Expand All @@ -14,7 +15,7 @@ class NftListingService(
private val redisService: RedisService,
) {

fun update(newListing: ListingResponse): Mono<Void> {
fun update(newListing: SaleResponse): Mono<Void> {
return when (newListing.statusType) {
StatusType.RESERVATION -> {
save(newListing)
Expand All @@ -37,7 +38,7 @@ class NftListingService(
else -> Mono.empty()
}
}
fun save(listing: ListingResponse) : Mono<NftListing> {
fun save(listing: SaleResponse) : Mono<NftListing> {
return nftListingRepository.save(
NftListing(
id = listing.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MoralisApiService(
ChainType.LINEA_SEPOLIA -> "0xe705"
ChainType.ETHEREUM_HOLESKY -> "0x4268"
ChainType.ETHEREUM_SEPOLIA -> "0xaa36a7"
ChainType.POLYGON_AMOY -> "0xaa36a7"
ChainType.POLYGON_AMOY -> "0x13882"
}
return chain
}
Expand Down

0 comments on commit 27ffe01

Please sign in to comment.