Skip to content

Commit 675feea

Browse files
committed
feat: MOBILE-388 - add multi-chain NFT song api
1 parent 28fe469 commit 675feea

File tree

19 files changed

+222
-13
lines changed

19 files changed

+222
-13
lines changed

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ object Dependencies {
6969
const val SERVER_AUTH = "io.ktor:ktor-server-auth:$VERSION"
7070
const val SERVER_AUTH_JWT = "io.ktor:ktor-server-auth-jwt:$VERSION"
7171
const val SERVER_HTML_BUILDER = "io.ktor:ktor-server-html-builder:$VERSION"
72+
const val SERVER_COMPRESSION = "io.ktor:ktor-server-compression:$VERSION"
73+
const val SERVER_COMPRESSION_ZSTD = "io.ktor:ktor-server-compression-zstd:$VERSION"
7274
const val CLIENT_CORE = "io.ktor:ktor-client-core:$VERSION"
7375
const val CLIENT_CIO = "io.ktor:ktor-client-cio:$VERSION"
7476
const val CLIENT_OKHTTP = "io.ktor:ktor-client-okhttp:$VERSION"

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Versions {
3131
const val KOTLIN_PLUGIN = "2.3.0"
3232
const val KTLINT = "1.8.0"
3333
const val KTLINT_PLUGIN = "12.1.1"
34-
const val KTOR = "3.3.3"
34+
const val KTOR = "3.4.0"
3535
const val KTOR_FLYWAY = "3.3.0"
3636
const val LOGBACK = "1.5.23"
3737
const val MAVEN_PUBLISH = "0.35.0"

newm-server/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ dependencies {
5454
implementation(Dependencies.Ktor.SERVER_AUTH)
5555
implementation(Dependencies.Ktor.SERVER_AUTH_JWT)
5656
implementation(Dependencies.Ktor.SERVER_HTML_BUILDER)
57+
implementation(Dependencies.Ktor.SERVER_COMPRESSION)
58+
implementation(Dependencies.Ktor.SERVER_COMPRESSION_ZSTD)
5759
implementation(Dependencies.Ktor.CLIENT_CORE)
5860
implementation(Dependencies.Ktor.CLIENT_CIO)
5961
implementation(Dependencies.Ktor.CLIENT_OKHTTP)

newm-server/src/main/kotlin/io/newm/server/Application.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.ktor.server.application.Application
55
import io.ktor.server.routing.routing
66
import io.newm.server.auth.createAuthenticationRoutes
77
import io.newm.server.auth.installAuthentication
8+
import io.newm.server.compression.installCompression
89
import io.newm.server.content.installContentNegotiation
910
import io.newm.server.cors.installCORS
1011
import io.newm.server.curator.installCurator
@@ -20,6 +21,7 @@ import io.newm.server.features.earnings.createEarningsRoutes
2021
import io.newm.server.features.ethereum.createEthereumRoutes
2122
import io.newm.server.features.idenfy.createIdenfyRoutes
2223
import io.newm.server.features.marketplace.createMarketplaceRoutes
24+
import io.newm.server.features.nftsong.createNftSongRoutes
2325
import io.newm.server.features.paypal.createPayPalRoutes
2426
import io.newm.server.features.playlist.createPlaylistRoutes
2527
import io.newm.server.features.song.createSongRoutes
@@ -65,6 +67,7 @@ fun Application.module() {
6567
installCORS()
6668
installForwarder()
6769
installHealthCheck()
70+
installCompression()
6871

6972
routing {
7073
createStaticContentRoutes()
@@ -84,6 +87,7 @@ fun Application.module() {
8487
createOpenApiDocumentationRoutes()
8588
createEarningsRoutes()
8689
createPayPalRoutes()
90+
createNftSongRoutes()
8791
}
8892

8993
initializeDaemons()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.newm.server.compression
2+
3+
import io.ktor.server.application.Application
4+
import io.ktor.server.application.install
5+
import io.ktor.server.plugins.compression.Compression
6+
import io.ktor.server.plugins.compression.condition
7+
import io.ktor.server.plugins.compression.deflate
8+
import io.ktor.server.plugins.compression.gzip
9+
import io.ktor.server.plugins.compression.minimumSize
10+
import io.ktor.server.plugins.compression.zstd.zstd
11+
import io.ktor.server.request.path
12+
import io.newm.shared.ktx.getConfigLong
13+
import io.newm.shared.ktx.getConfigStrings
14+
15+
fun Application.installCompression() {
16+
val minSize = environment.getConfigLong("compression.minSize")
17+
val pathPrefixes = environment.getConfigStrings("compression.pathPrefixes")
18+
19+
install(Compression) {
20+
minimumSize(minSize)
21+
condition {
22+
val path = request.path()
23+
pathPrefixes.any(path::startsWith)
24+
}
25+
26+
zstd { priority = 1.0 }
27+
gzip { priority = 0.9 }
28+
deflate { priority = 0.8 }
29+
}
30+
}

newm-server/src/main/kotlin/io/newm/server/di/DependencyInjectionInstall.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import io.newm.server.features.idenfy.idenfyKoinModule
2222
import io.newm.server.features.marketplace.marketplaceKoinModule
2323
import io.newm.server.features.minting.mintingKoinModule
2424
import io.newm.server.features.nftcdn.nftCdnKoinModule
25+
import io.newm.server.features.nftsong.nftSongKoinModule
2526
import io.newm.server.features.paypal.payPalKoinModule
2627
import io.newm.server.features.playlist.playlistKoinModule
2728
import io.newm.server.features.referralhero.referralHeroKoinModule
@@ -74,6 +75,7 @@ fun Application.installDependencyInjection() {
7475
dripDropzKoinModule,
7576
referralHeroKoinModule,
7677
payPalKoinModule,
78+
nftSongKoinModule,
7779
)
7880
}
7981
}

newm-server/src/main/kotlin/io/newm/server/features/ethereum/EthereumModule.kt renamed to newm-server/src/main/kotlin/io/newm/server/features/ethereum/EthereumKoinModule.kt

File renamed without changes.

newm-server/src/main/kotlin/io/newm/server/features/ethereum/EthereumRoutes.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import io.ktor.server.response.respond
55
import io.ktor.server.routing.Routing
66
import io.newm.server.auth.jwt.AUTH_JWT
77
import io.newm.server.features.ethereum.repo.EthereumRepository
8-
import io.newm.server.ktx.requiredQueryParam
8+
import io.newm.server.ktx.myUserId
99
import io.newm.shared.koin.inject
1010
import io.newm.shared.ktx.get
1111

@@ -14,9 +14,7 @@ fun Routing.createEthereumRoutes() {
1414

1515
authenticate(AUTH_JWT) {
1616
get("/v1/ethereum/nft/songs") {
17-
// TODO: for now, during the initial experimentation phase, we get the owner address directly from
18-
// the client, later we will migrate to a Wallet connection model similar to Cardano
19-
respond(repository.getNftSongs(request.requiredQueryParam("ownerAddress")))
17+
respond(repository.getWalletNftSongs(myUserId))
2018
}
2119
}
2220
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package io.newm.server.features.ethereum.repo
22

33
import io.newm.server.features.ethereum.model.EthereumNftSong
4+
import io.newm.server.typealiases.UserId
45

56
interface EthereumRepository {
6-
suspend fun getNftSongs(ownerAddress: String): List<EthereumNftSong>
7+
suspend fun getWalletNftSongs(userId: UserId): List<EthereumNftSong>
78
}

newm-server/src/main/kotlin/io/newm/server/features/ethereum/repo/EthereumRepositoryImpl.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@ import io.newm.server.features.ethereum.model.EthereumNft
1212
import io.newm.server.features.ethereum.model.EthereumNftSong
1313
import io.newm.server.features.ethereum.model.GetNftsByOwnerResponse
1414
import io.newm.server.features.ethereum.parser.parseSong
15+
import io.newm.server.features.user.database.UserEntity
1516
import io.newm.server.ktx.checkedBody
1617
import io.newm.server.ktx.getSecureConfigString
18+
import io.newm.server.typealiases.UserId
1719
import io.newm.shared.ktx.getConfigString
20+
import org.jetbrains.exposed.sql.transactions.transaction
1821

1922
internal class EthereumRepositoryImpl(
2023
private val client: HttpClient,
2124
private val environment: ApplicationEnvironment
2225
) : EthereumRepository {
2326
private val logger = KotlinLogging.logger {}
2427

25-
override suspend fun getNftSongs(ownerAddress: String): List<EthereumNftSong> {
26-
logger.debug { "getNftSongs: ownerAddress = $ownerAddress" }
28+
override suspend fun getWalletNftSongs(userId: UserId): List<EthereumNftSong> {
29+
logger.debug { "getWalletNftSongs: userId = $userId" }
30+
31+
// Temporary test hook until Ethereum wallet connections are implemented
32+
val email = transaction { UserEntity[userId].email }
33+
if (!email.endsWith("@newm.io")) return emptyList()
34+
val address = "0x89fd6e1e7a737293dc9ecaee118753b7abdf5e37"
2735

2836
val apiUrl = environment.getConfigString("alchemy.apiUrl")
2937
val apiKey = environment.getSecureConfigString("alchemy.apiKey")
@@ -34,7 +42,7 @@ internal class EthereumRepositoryImpl(
3442
delayMillis { 500L }
3543
}
3644
accept(ContentType.Application.Json)
37-
parameter("owner", ownerAddress)
45+
parameter("owner", address)
3846
}.checkedBody<GetNftsByOwnerResponse>()
3947
.ownedNfts
4048
.mapNotNull(EthereumNft::parseSong)

0 commit comments

Comments
 (0)