6 Create minimal Server-API for client tests - basics
This commit is contained in:
1 parent
5ce25ff422
commit
b8f924b578
17 files changed
+107
-37
No files matched your search
@@ -1,3 +1,3 @@
|
||||
#auto generated
|
||||
#Sun Feb 08 23:42:57 CET 2026
|
||||
build.number=43
|
||||
#Tue Feb 10 00:04:01 CET 2026
|
||||
build.number=50
|
||||
@@ -3,10 +3,7 @@ package net.keinekekse.app
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.ktor.server.application.*
|
||||
import net.keinekekse.app.server.VERSION
|
||||
import net.keinekekse.app.server.config.configureDatabase
|
||||
import net.keinekekse.app.server.config.configureKoin
|
||||
import net.keinekekse.app.server.config.configureRouting
|
||||
import net.keinekekse.app.server.config.configureSecurity
|
||||
import net.keinekekse.app.server.config.*
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
@@ -22,13 +19,22 @@ fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
||||
//}
|
||||
|
||||
fun Application.module() {
|
||||
logger.info { "\n**\n** Starting ${VERSION.displayName} - ${VERSION.description} ${VERSION.fullVersion}\n**" }
|
||||
logger.info {
|
||||
"""
|
||||
|
||||
**
|
||||
** Starting ${VERSION.displayName} - ${VERSION.description} ${VERSION.fullVersion}
|
||||
**
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
configureSerialization()
|
||||
configureKoin()
|
||||
configureSecurity()
|
||||
configureRouting()
|
||||
configureDatabase()
|
||||
|
||||
configureRouting()
|
||||
|
||||
/* // DB-Test
|
||||
transaction {
|
||||
|
||||
|
||||
@@ -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.43"
|
||||
override val fullVersion = "0.1.0-beta.1+build.43"
|
||||
override val version = "0.1.0-beta.1+build.50"
|
||||
override val fullVersion = "0.1.0-beta.1+build.50"
|
||||
override val major = 0
|
||||
override val minor = 1
|
||||
override val patch = 0
|
||||
override val preRelease = "beta.1"
|
||||
override val buildMetadata = "build.43"
|
||||
override val buildDate = "2026-02-08T22:42:57.727025Z"
|
||||
override val buildMetadata = "build.50"
|
||||
override val buildDate = "2026-02-09T23:04:01.715682Z"
|
||||
override val displayName = "kAS"
|
||||
override val copyright = "Copyright (c) 2026 Hartmut Bauer"
|
||||
override val name = "server"
|
||||
|
||||
@@ -2,12 +2,12 @@ package net.keinekekse.app.server.config
|
||||
|
||||
import io.ktor.server.application.*
|
||||
import net.keinekekse.app.server.di.KoinApp
|
||||
import org.koin.dsl.koinConfiguration
|
||||
import org.koin.ktor.plugin.Koin
|
||||
import org.koin.logger.slf4jLogger
|
||||
import org.koin.plugin.module.dsl.withConfiguration
|
||||
|
||||
fun Application.configureKoin() {
|
||||
koinConfiguration {
|
||||
install(Koin) {
|
||||
slf4jLogger()
|
||||
withConfiguration<KoinApp>()
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.ktor.server.auth.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import net.keinekekse.app.server.VERSION
|
||||
import net.keinekekse.app.server.testdb.testDbRoute
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
@@ -22,5 +23,7 @@ fun Application.configureRouting() {
|
||||
call.respondText("Ktor ${VERSION.displayName} ${VERSION.fullVersion} - principal=${principal?.name}")
|
||||
}
|
||||
}
|
||||
|
||||
testDbRoute()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.keinekekse.app.server.config
|
||||
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
|
||||
fun Application.configureSerialization() {
|
||||
install(ContentNegotiation) {
|
||||
json(
|
||||
json = kotlinx.serialization.json.Json {
|
||||
prettyPrint = true
|
||||
// isLenient = true
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.keinekekse.app.server.testdb.db
|
||||
|
||||
import net.keinekekse.app.server.testdb.model.*
|
||||
import net.keinekekse.app.book.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
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package net.keinekekse.app.server.testdb.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Artist(
|
||||
val id: Int = 0,
|
||||
val name: String = "",
|
||||
val givenName: String = "",
|
||||
)
|
||||
@@ -1,9 +0,0 @@
|
||||
package net.keinekekse.app.server.testdb.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ArtistRole(
|
||||
val id: Int = 0,
|
||||
val role: String = "",
|
||||
)
|
||||
@@ -1,16 +0,0 @@
|
||||
package net.keinekekse.app.server.testdb.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ArtistForBook(val artist: Artist, val role: ArtistRole)
|
||||
|
||||
@Serializable
|
||||
data class Book(
|
||||
val id: Int = 0,
|
||||
val title: String = "",
|
||||
val series: Series? = null,
|
||||
val seriesIndex: Int = 0,
|
||||
|
||||
val artists: List<ArtistForBook> = emptyList(),
|
||||
)
|
||||
@@ -1,5 +1,9 @@
|
||||
package net.keinekekse.app.server.testdb.model
|
||||
|
||||
import net.keinekekse.app.book.model.Artist
|
||||
import net.keinekekse.app.book.model.Book
|
||||
import net.keinekekse.app.book.model.Series
|
||||
|
||||
interface BookRepository {
|
||||
suspend fun allBooks(): List<Book>
|
||||
suspend fun bookById(id: Int): Book?
|
||||
|
||||
+13
-4
@@ -1,12 +1,21 @@
|
||||
package net.keinekekse.app.server.testdb.model
|
||||
|
||||
import net.keinekekse.app.book.model.Artist
|
||||
import net.keinekekse.app.book.model.Book
|
||||
import net.keinekekse.app.book.model.Series
|
||||
import net.keinekekse.app.server.testdb.db.BookDAO
|
||||
import net.keinekekse.app.server.testdb.db.daoToModel
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.suspendTransaction
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@Single
|
||||
class BookRepositoryImpl : BookRepository {
|
||||
override suspend fun allBooks(): List<Book> {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun allBooks(): List<Book> = suspendTransaction {
|
||||
BookDAO.all().map(::daoToModel)
|
||||
}
|
||||
|
||||
override suspend fun bookById(id: Int): Book? {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun bookById(id: Int): Book? = suspendTransaction {
|
||||
BookDAO.findById(id)?.let { daoToModel(it) }
|
||||
}
|
||||
|
||||
override suspend fun booksBySeries(series: Series): List<Book> {
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package net.keinekekse.app.server.testdb.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Series(val id: Int, val name: String)
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.keinekekse.app.server.testdb
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import net.keinekekse.app.server.testdb.model.BookRepository
|
||||
import org.koin.ktor.ext.inject
|
||||
|
||||
fun Route.testDbRoute() {
|
||||
val repository: BookRepository by inject<BookRepository>()
|
||||
|
||||
// authenticate("auth-KC") {
|
||||
route("/testdb") {
|
||||
get("/books") {
|
||||
// call.respondText("Test DB route")
|
||||
val books = repository.allBooks()
|
||||
call.respond(books)
|
||||
}
|
||||
get("/book/{id}") {
|
||||
// TODO safe toInt conv
|
||||
val id = call.parameters["id"]!!.toInt()
|
||||
repository.bookById(id)?.let { call.respond(it) }
|
||||
?: call.respondText("Book with id $id not found", status = HttpStatusCode.NotFound)
|
||||
}
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user