-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STUD-380 | Added GetSongSmartLinks API
- Loading branch information
Showing
12 changed files
with
229 additions
and
3 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
29 changes: 29 additions & 0 deletions
29
newm-server/src/main/kotlin/io/newm/server/database/migration/V72__CreateSongSmartLinks.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,29 @@ | ||
package io.newm.server.database.migration | ||
|
||
import org.flywaydb.core.api.migration.BaseJavaMigration | ||
import org.flywaydb.core.api.migration.Context | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
|
||
@Suppress("unused") | ||
class V72__CreateSongSmartLinks : BaseJavaMigration() { | ||
override fun migrate(context: Context?) { | ||
transaction { | ||
execInBatch( | ||
listOf( | ||
""" | ||
CREATE TABLE IF NOT EXISTS song_smart_links ( | ||
id uuid PRIMARY KEY, | ||
created_at timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
song_id uuid NOT NULL, | ||
store_name TEXT NOT NULL, | ||
url TEXT NOT NULL, | ||
CONSTRAINT fk_song_smart_links_song_id__id FOREIGN KEY (song_id) REFERENCES songs(id) ON DELETE NO ACTION | ||
) | ||
""".trimIndent(), | ||
"CREATE INDEX IF NOT EXISTS song_smart_links_song_id_index ON song_smart_links(song_id)", | ||
"INSERT INTO config VALUES ('songSmartLinks.cacheTimeToLive','172800') ON CONFLICT(id) DO NOTHING", | ||
), | ||
) | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...erver/src/main/kotlin/io/newm/server/features/distribution/model/GetSmartLinksResponse.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,14 @@ | ||
package io.newm.server.features.distribution.model | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GetSmartLinksResponse( | ||
@SerialName("success") | ||
val success: Boolean, | ||
@SerialName("message") | ||
val message: String? = null, | ||
@SerialName("data") | ||
val data: List<SmartLink>? = null, | ||
) |
12 changes: 12 additions & 0 deletions
12
newm-server/src/main/kotlin/io/newm/server/features/distribution/model/SmartLink.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,12 @@ | ||
package io.newm.server.features.distribution.model | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SmartLink( | ||
@SerialName("store_name") | ||
val storeName: String, | ||
@SerialName("smart_link_url") | ||
val url: String | ||
) |
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
31 changes: 31 additions & 0 deletions
31
newm-server/src/main/kotlin/io/newm/server/features/song/database/SongSmartLinkEntity.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,31 @@ | ||
package io.newm.server.features.song.database | ||
|
||
import io.newm.server.features.song.model.SongSmartLink | ||
import io.newm.server.typealiases.SongId | ||
import org.jetbrains.exposed.dao.UUIDEntity | ||
import org.jetbrains.exposed.dao.UUIDEntityClass | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
|
||
class SongSmartLinkEntity( | ||
id: EntityID<UUID> | ||
) : UUIDEntity(id) { | ||
val createdAt: LocalDateTime by SongSmartLinkTable.createdAt | ||
var songId: EntityID<SongId> by SongSmartLinkTable.songId | ||
var storeName: String by SongSmartLinkTable.storeName | ||
var url: String by SongSmartLinkTable.url | ||
|
||
fun toModel(): SongSmartLink = | ||
SongSmartLink( | ||
id = id.value, | ||
storeName = storeName, | ||
url = url | ||
) | ||
|
||
companion object : UUIDEntityClass<SongSmartLinkEntity>(SongSmartLinkTable) { | ||
fun findBySongId( | ||
songId: SongId | ||
): List<SongSmartLinkEntity> = find { SongSmartLinkTable.songId eq songId }.toList() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
newm-server/src/main/kotlin/io/newm/server/features/song/database/SongSmartLinkTable.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 io.newm.server.features.song.database | ||
|
||
import io.newm.server.typealiases.SongId | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
import org.jetbrains.exposed.dao.id.UUIDTable | ||
import org.jetbrains.exposed.sql.Column | ||
import org.jetbrains.exposed.sql.ReferenceOption | ||
import org.jetbrains.exposed.sql.javatime.CurrentDateTime | ||
import org.jetbrains.exposed.sql.javatime.datetime | ||
import java.time.LocalDateTime | ||
|
||
object SongSmartLinkTable : UUIDTable(name = "song_smart_links") { | ||
val createdAt: Column<LocalDateTime> = datetime("created_at").defaultExpression(CurrentDateTime) | ||
val songId: Column<EntityID<SongId>> = reference("song_id", SongTable, onDelete = ReferenceOption.NO_ACTION).index() | ||
val storeName: Column<String> = text("store_name") | ||
val url: Column<String> = text("url") | ||
} |
13 changes: 13 additions & 0 deletions
13
newm-server/src/main/kotlin/io/newm/server/features/song/model/SongSmartLink.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,13 @@ | ||
package io.newm.server.features.song.model | ||
|
||
import kotlinx.serialization.Contextual | ||
import kotlinx.serialization.Serializable | ||
import java.util.UUID | ||
|
||
@Serializable | ||
data class SongSmartLink( | ||
@Contextual | ||
val id: UUID, | ||
val storeName: String, | ||
val url: String | ||
) |
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