initial commit
This commit is contained in:
commit
d84861949f
92 files changed
+8425
No files matched your search
@@ -0,0 +1,91 @@
|
||||
package net.keinekekse.app.books.db.schema
|
||||
|
||||
import net.keinekekse.app.books.model.*
|
||||
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 BooksTable : IntIdTable("books") {
|
||||
var title = varchar("title", 150).index()
|
||||
var subTitle = varchar("sub_title", 150).nullable()
|
||||
var originalTitle = varchar("original_title", 150).nullable()
|
||||
var year = integer("year")
|
||||
var originalYear = integer("original_year").nullable()
|
||||
var language = varchar("language", 2)
|
||||
var isbn = varchar("isbn", 13).index()
|
||||
var publisher = reference("publisher_id", PublisherTable.id)
|
||||
var series = optReference("series_id", SeriesTable.id)
|
||||
var seriesIndex = integer("seriesIndex").nullable()
|
||||
var comments = varchar("comments", 255)
|
||||
var parentBook = optReference("parent_book_id", id)
|
||||
val cover = blob("cover").nullable()
|
||||
}
|
||||
|
||||
class BookDAO(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<BookDAO>(BooksTable)
|
||||
|
||||
var title by BooksTable.title
|
||||
var subTitle by BooksTable.subTitle
|
||||
var seriesIndex by BooksTable.seriesIndex
|
||||
var originalTitle by BooksTable.originalTitle
|
||||
var year by BooksTable.year
|
||||
var originalYear by BooksTable.originalYear
|
||||
var language: Languages by BooksTable.language.transform({ it.name }, { Languages.valueOf(it) })
|
||||
var isbn by BooksTable.isbn
|
||||
var publisher by PublisherDAO.Companion referencedOn BooksTable.publisher
|
||||
var comments by BooksTable.comments
|
||||
var cover by BooksTable.cover
|
||||
|
||||
var series by SeriesDAO.Companion optionalReferencedOn BooksTable.series
|
||||
val artists by ArtistToBookDAO referrersOn ArtistToBookTable.bookId
|
||||
val tags by TagsToBookDAO referrersOn TagsToBookTable.bookId
|
||||
|
||||
// Verweis auf Sammelband (falls dieses Buch ein Teilroman ist)
|
||||
var parentBook by BookDAO optionalReferencedOn BooksTable.parentBook
|
||||
|
||||
// Enthaltene Einzelromane (falls dieses Buch der Sammelband ist)
|
||||
val containedBooks by BookDAO optionalReferrersOn BooksTable.parentBook
|
||||
}
|
||||
|
||||
fun bookDaoToModel(dao: BookDAO, includeChildren: Boolean = true): Book = Book(
|
||||
dao.id.value,
|
||||
dao.title,
|
||||
dao.subTitle,
|
||||
dao.originalTitle,
|
||||
dao.year,
|
||||
dao.originalYear,
|
||||
dao.language,
|
||||
dao.isbn,
|
||||
publisher = Publisher(dao.publisher.id.value, dao.publisher.name),
|
||||
dao.comments,
|
||||
cover = dao.cover?.bytes ?: ByteArray(0),
|
||||
|
||||
series = if (dao.series != null) Series(dao.series!!.id.value, dao.series!!.name) else null,
|
||||
seriesIndex = dao.seriesIndex,
|
||||
|
||||
dao.parentBook?.id?.value,
|
||||
containedBooks = if (includeChildren) {
|
||||
dao.containedBooks.map { bookDaoToModel(it, includeChildren = false) }
|
||||
} else {
|
||||
emptyList()
|
||||
},
|
||||
|
||||
artists = dao.artists.map {
|
||||
ArtistForBook(
|
||||
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)
|
||||
},
|
||||
)
|
||||
|
||||
fun emptyBook(title: String = "", year: Int = 0, isbn: String = ""): Book =
|
||||
Book(
|
||||
title = title,
|
||||
year = year,
|
||||
isbn = isbn,
|
||||
publisher = Publisher(0, ""),
|
||||
)
|
||||
Reference in new issue
Block a user