#6 Datenmodell ausgebaut

This commit is contained in:
Hartmut Bauer committed 2026-02-13 00:55:11 +01:00
1 parent e8bd21d108
commit e96142b762
10 files changed
+91 -14

No files matched your search

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