Skip to content

Commit

Permalink
Added smart links to GetMarketplaceSales response
Browse files Browse the repository at this point in the history
  • Loading branch information
wlara committed Jan 17, 2025
1 parent 3871135 commit 3633d2a
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import org.koin.dsl.module
val marketplaceKoinModule =
module {
single<Daemon> { MarketplaceMonitorDaemon(get(), get(), get()) }
single<MarketplaceRepository> { MarketplaceRepositoryImpl(get(), get(), get(), get()) }
single<MarketplaceRepository> { MarketplaceRepositoryImpl(get(), get(), get(), get(), get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.newm.server.features.nftcdn.repo.NftCdnRepository
import io.newm.server.features.song.database.ReleaseEntity
import io.newm.server.features.song.database.SongEntity
import io.newm.server.features.song.database.SongTable
import io.newm.server.features.song.model.SongSmartLink
import io.newm.server.features.user.database.UserEntity
import io.newm.server.features.user.database.UserTable
import io.newm.server.ktx.arweaveToWebUrl
Expand Down Expand Up @@ -68,7 +69,8 @@ class MarketplaceSaleEntity(
fun toModel(
isMainnet: Boolean,
isNftCdnEnabled: Boolean,
costAmountConversions: CostAmountConversions
costAmountConversions: CostAmountConversions,
smartLinks: List<SongSmartLink>
): Sale {
val song = SongEntity[songId]
val artist = UserEntity[song.ownerId]
Expand Down Expand Up @@ -133,6 +135,7 @@ class MarketplaceSaleEntity(
)
}
}.sortedBy { it.name },
smartLinks = smartLinks
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.newm.server.features.marketplace.model

import io.newm.server.features.song.model.SongSmartLink
import io.newm.server.typealiases.SaleId
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -44,6 +45,7 @@ data class Sale(
val tokenAgreementUrl: String?,
val assetUrl: String?,
val collaborators: List<SongCollaborator>?,
val smartLinks: List<SongSmartLink>
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import io.newm.server.features.marketplace.parser.parseQueue
import io.newm.server.features.marketplace.parser.parseSale
import io.newm.server.features.song.database.SongEntity
import io.newm.server.features.song.database.SongTable
import io.newm.server.features.song.repo.SongRepository
import io.newm.server.ktx.toReferenceUtxo
import io.newm.server.typealiases.UserId
import io.newm.shared.exception.HttpNotFoundException
Expand Down Expand Up @@ -107,7 +108,8 @@ internal class MarketplaceRepositoryImpl(
private val environment: ApplicationEnvironment,
private val configRepository: ConfigRepository,
private val cardanoRepository: CardanoRepository,
private val emailRepository: EmailRepository
private val emailRepository: EmailRepository,
private val songRepository: SongRepository
) : MarketplaceRepository {
private val log = KotlinLogging.logger {}

Expand All @@ -117,7 +119,8 @@ internal class MarketplaceRepositoryImpl(
val isMainnet = cardanoRepository.isMainnet()
val isNftCdnEnabled = configRepository.getBoolean(CONFIG_KEY_NFTCDN_ENABLED)
val costAmountConversions = sale.computeCostAmountConversions()
return transaction { sale.toModel(isMainnet, isNftCdnEnabled, costAmountConversions) }
val smartLinks = songRepository.getSmartLinks(sale.songId.value)
return transaction { sale.toModel(isMainnet, isNftCdnEnabled, costAmountConversions, smartLinks) }
}

override suspend fun getSales(
Expand All @@ -135,9 +138,10 @@ internal class MarketplaceRepositoryImpl(
.limit(count = limit)
.toList()
}
val costAmountConversions = sales.associate { it.id.value to it.computeCostAmountConversions() }
val conversions = sales.associate { it.id.value to it.computeCostAmountConversions() }
val smartLinks = sales.associate { it.id.value to songRepository.getSmartLinks(it.songId.value) }
return transaction {
sales.map { it.toModel(isMainnet, isNftCdnEnabled, costAmountConversions[it.id.value]!!) }
sales.map { it.toModel(isMainnet, isNftCdnEnabled, conversions[it.id.value]!!, smartLinks[it.id.value]!!) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.newm.server.features.song.database.ReleaseEntity
import io.newm.server.features.song.database.ReleaseTable
import io.newm.server.features.song.database.SongEntity
import io.newm.server.features.song.database.SongReceiptTable
import io.newm.server.features.song.database.SongSmartLinkTable
import io.newm.server.features.song.database.SongTable
import io.newm.server.features.song.model.Release
import io.newm.server.features.song.model.ReleaseType
Expand Down Expand Up @@ -154,6 +155,7 @@ open class BaseApplicationTests {
TwoFactorAuthTable,
KeyTable,
SongTable,
SongSmartLinkTable,
CollaborationTable,
PlaylistTable,
SongsInPlaylistsTable,
Expand Down
Loading

0 comments on commit 3633d2a

Please sign in to comment.