#6 Datenmodell ausgebaut
This commit is contained in:
1 parent
e8bd21d108
commit
e96142b762
10 files changed
+91
-14
No files matched your search
@@ -1,3 +1,3 @@
|
||||
#auto generated
|
||||
#Tue Feb 10 23:59:14 CET 2026
|
||||
build.number=62
|
||||
#Fri Feb 13 00:48:17 CET 2026
|
||||
build.number=64
|
||||
@@ -3,8 +3,13 @@ package net.keinekekse.app.server
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.netty.*
|
||||
//import net.keinekekse.app.books.model.Languages
|
||||
//import net.keinekekse.app.server.books.db.*
|
||||
import net.keinekekse.app.server.config.*
|
||||
|
||||
//import org.jetbrains.exposed.v1.jdbc.SchemaUtils
|
||||
//import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
fun main(args: Array<String>): Unit = EngineMain.main(args)
|
||||
@@ -41,6 +46,8 @@ fun Application.module() {
|
||||
|
||||
// create if not exists
|
||||
SchemaUtils.drop(
|
||||
TagsTable,
|
||||
TagsToBookTable,
|
||||
SeriesTable,
|
||||
ArtistToBookTable,
|
||||
ArtistRolesTable,
|
||||
@@ -48,6 +55,8 @@ fun Application.module() {
|
||||
BooksTable
|
||||
)
|
||||
SchemaUtils.create(
|
||||
TagsTable,
|
||||
TagsToBookTable,
|
||||
SeriesTable,
|
||||
ArtistRolesTable,
|
||||
ArtistsTable,
|
||||
@@ -85,14 +94,18 @@ fun Application.module() {
|
||||
originalTitle = ""
|
||||
year = 2024
|
||||
seriesIndex = 0
|
||||
language = Languages.EN.name
|
||||
language = Languages.EN
|
||||
isbn = "9781617296823"
|
||||
publisher = "Manning"
|
||||
}
|
||||
val kp = BookDAO.new {
|
||||
title = "Kotlin Design Patterns and Best Practices, 3rd Edition"
|
||||
originalTitle = ""
|
||||
year = 2024
|
||||
seriesIndex = 0
|
||||
language = Languages.EN.name
|
||||
language = Languages.EN
|
||||
isbn = "9781617298823"
|
||||
publisher = "Packt Publishing"
|
||||
}
|
||||
|
||||
ArtistToBookDAO.new {
|
||||
|
||||
@@ -3,14 +3,14 @@ package net.keinekekse.app.server
|
||||
import net.keinekekse.version.Version
|
||||
|
||||
object VERSION: Version {
|
||||
override val version = "0.1.0-beta.1+build.62"
|
||||
override val fullVersion = "0.1.0-beta.1+build.62"
|
||||
override val version = "0.1.0-beta.1+build.64"
|
||||
override val fullVersion = "0.1.0-beta.1+build.64"
|
||||
override val major = 0
|
||||
override val minor = 1
|
||||
override val patch = 0
|
||||
override val preRelease = "beta.1"
|
||||
override val buildMetadata = "build.62"
|
||||
override val buildDate = "2026-02-10T22:59:14.710093Z"
|
||||
override val buildMetadata = "build.64"
|
||||
override val buildDate = "2026-02-12T23:48:17.731367Z"
|
||||
override val displayName = "kAS"
|
||||
override val copyright = "Copyright (c) 2026 Hartmut Bauer"
|
||||
override val name = "server"
|
||||
|
||||
@@ -15,6 +15,6 @@ class ArtistToBookDAO(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<ArtistToBookDAO>(ArtistToBookTable)
|
||||
|
||||
var artist by ArtistDAO referencedOn ArtistToBookTable.artistId
|
||||
var book by BookDAO.Companion referencedOn ArtistToBookTable.bookId
|
||||
var book by BookDAO referencedOn ArtistToBookTable.bookId
|
||||
var role by ArtistRoleDAO referencedOn ArtistToBookTable.role
|
||||
}
|
||||
@@ -11,6 +11,8 @@ object BooksTable : IntIdTable("books") {
|
||||
var originalTitle = varchar("original_title", 100)
|
||||
var year = integer("year")
|
||||
var language = varchar("language", 2)
|
||||
var isbn = varchar("isbn", 13)
|
||||
var publisher = varchar("publisher", 100)
|
||||
var series = optReference("series_id", SeriesTable.id)
|
||||
var seriesIndex = integer("seriesIndex")
|
||||
}
|
||||
@@ -23,9 +25,12 @@ class BookDAO(id: EntityID<Int>) : IntEntity(id) {
|
||||
var originalTitle by BooksTable.originalTitle
|
||||
var year by BooksTable.year
|
||||
var language: Languages by BooksTable.language.transform({ it.name }, { Languages.valueOf(it) })
|
||||
var isbn by BooksTable.isbn
|
||||
var publisher by BooksTable.publisher
|
||||
|
||||
var series by SeriesDAO.Companion optionalReferencedOn BooksTable.series
|
||||
val artists by ArtistToBookDAO referrersOn ArtistToBookTable.bookId
|
||||
val tags by TagsToBookDAO referrersOn TagsToBookTable.bookId
|
||||
}
|
||||
|
||||
fun daoToModel(dao: BookDAO) = Book(
|
||||
@@ -34,6 +39,8 @@ fun daoToModel(dao: BookDAO) = Book(
|
||||
dao.originalTitle,
|
||||
dao.year,
|
||||
dao.language,
|
||||
dao.isbn,
|
||||
dao.publisher,
|
||||
series = if (dao.series != null) Series(dao.series!!.id.value, dao.series!!.name) else null,
|
||||
seriesIndex = dao.seriesIndex,
|
||||
artists = dao.artists.map {
|
||||
@@ -41,5 +48,8 @@ fun daoToModel(dao: BookDAO) = Book(
|
||||
Artist(it.artist.id.value, it.artist.name, it.artist.givenName),
|
||||
ArtistRole(it.role.id.value, it.role.role)
|
||||
)
|
||||
}
|
||||
},
|
||||
tags = dao.tags.map {
|
||||
Tag(it.tag.id.value, it.tag.tag)
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.keinekekse.app.server.books.db
|
||||
|
||||
import net.keinekekse.app.books.model.Tag
|
||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.v1.dao.IntEntity
|
||||
import org.jetbrains.exposed.v1.dao.IntEntityClass
|
||||
|
||||
object TagsTable : IntIdTable("tags") {
|
||||
var tag = varchar("tag", 20)
|
||||
}
|
||||
|
||||
class TagsDAO(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<TagsDAO>(TagsTable)
|
||||
|
||||
var tag by TagsTable.tag
|
||||
}
|
||||
|
||||
fun daoToModel(dao: TagsDAO): Tag = Tag(dao.id.value, dao.tag)
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.keinekekse.app.server.books.db
|
||||
|
||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.v1.dao.IntEntity
|
||||
import org.jetbrains.exposed.v1.dao.IntEntityClass
|
||||
|
||||
object TagsToBookTable : IntIdTable("tag_to_book") {
|
||||
var tagId = reference("tag_id", TagsTable.id)
|
||||
var bookId = reference("book_id", BooksTable.id)
|
||||
}
|
||||
|
||||
class TagsToBookDAO(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<TagsToBookDAO>(TagsToBookTable)
|
||||
|
||||
var tag by TagsDAO referencedOn TagsToBookTable.tagId
|
||||
var book by BookDAO referencedOn TagsToBookTable.bookId
|
||||
}
|
||||
@@ -3,10 +3,13 @@ package net.keinekekse.app.server.books.model
|
||||
import net.keinekekse.app.books.model.Artist
|
||||
import net.keinekekse.app.books.model.Book
|
||||
import net.keinekekse.app.books.model.Series
|
||||
import net.keinekekse.app.server.books.db.ArtistToBookTable
|
||||
import net.keinekekse.app.server.books.db.BookDAO
|
||||
import net.keinekekse.app.server.books.db.BooksTable
|
||||
import net.keinekekse.app.server.books.db.daoToModel
|
||||
import org.jetbrains.exposed.v1.core.and
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.like
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.suspendTransaction
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@@ -20,16 +23,21 @@ class BookRepositoryImpl : BookRepository {
|
||||
BookDAO.findById(id)?.let { daoToModel(it) }
|
||||
}
|
||||
|
||||
// TODO noch zu testen
|
||||
override suspend fun booksBySeries(series: Series): List<Book> = suspendTransaction {
|
||||
BookDAO.find { BooksTable.series eq series.id }.map(::daoToModel)
|
||||
}
|
||||
|
||||
override suspend fun bookByTitle(title: String): List<Book> {
|
||||
TODO("Not yet implemented")
|
||||
// TODO noch zu testen
|
||||
override suspend fun bookByTitle(title: String): List<Book> = suspendTransaction {
|
||||
val comp = "%$title%"
|
||||
BookDAO.find { BooksTable.title like comp }.map(::daoToModel)
|
||||
}
|
||||
|
||||
override suspend fun booksByArtist(artist: Artist): List<Book> {
|
||||
TODO("Not yet implemented")
|
||||
// TODO noch zu testen
|
||||
override suspend fun booksByArtist(artist: Artist): List<Book> = suspendTransaction {
|
||||
BookDAO.find { (ArtistToBookTable.artistId eq artist.id) and (ArtistToBookTable.bookId eq BooksTable.id) }
|
||||
.map(::daoToModel)
|
||||
}
|
||||
|
||||
override suspend fun addTBook(book: Book) {
|
||||
|
||||
@@ -12,8 +12,11 @@ data class Book(
|
||||
val originalTitle: String = "",
|
||||
val year: Int = 0,
|
||||
val language: Languages = Languages.DE,
|
||||
val isbn: String = "",
|
||||
val publisher: String = "",
|
||||
val series: Series? = null,
|
||||
val seriesIndex: Int = 0,
|
||||
|
||||
val artists: List<ArtistForBook> = emptyList(),
|
||||
val tags: List<Tag> = emptyList(),
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.keinekekse.app.books.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Tag(val id: Int, val tag: String)
|
||||
Reference in new issue
Block a user