Add Fight Delete
Dieser Commit ist enthalten in:
Ursprung
84a1ce87c6
Commit
0b670cd016
@ -23,17 +23,13 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("io.ktor:ktor-server-auto-head-response-jvm:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-caching-headers-jvm:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-compression-jvm:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-cors-jvm:$ktor_version")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
|
||||
implementation("ch.qos.logback:logback-classic:$logback_version")
|
||||
implementation("io.ktor:ktor-server-host-common-jvm:2.2.1")
|
||||
implementation("io.ktor:ktor-server-status-pages-jvm:2.2.1")
|
||||
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
|
||||
implementation("io.ktor:ktor-server-request-validation:$ktor_version")
|
||||
|
@ -1,46 +1,15 @@
|
||||
package de.steamwar.plugins
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.autohead.*
|
||||
import io.ktor.server.plugins.cachingheaders.*
|
||||
import io.ktor.server.plugins.compression.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.server.plugins.cors.routing.*
|
||||
import io.ktor.server.plugins.statuspages.*
|
||||
import io.ktor.server.response.*
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
data class Session(val name: String)
|
||||
|
||||
fun Application.configurePlugins() {
|
||||
install(AutoHeadResponse)
|
||||
|
||||
install(CachingHeaders) {
|
||||
options { call, outgoingContent ->
|
||||
when (outgoingContent.contentType?.withoutParameters()) {
|
||||
ContentType.Text.CSS -> CachingOptions(CacheControl.MaxAge(maxAgeSeconds = 24 * 60 * 60))
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
install(Compression) {
|
||||
gzip {
|
||||
priority = 1.0
|
||||
}
|
||||
deflate {
|
||||
priority = 10.0
|
||||
minimumSize(1024) // condition
|
||||
}
|
||||
}
|
||||
install(StatusPages) {
|
||||
exception<Throwable> { call, cause ->
|
||||
call.respondText(text = "500: $cause\n${cause.stackTraceToString()}", status = HttpStatusCode.InternalServerError)
|
||||
}
|
||||
}
|
||||
install(CORS) {
|
||||
allowMethod(HttpMethod.Options)
|
||||
allowMethod(HttpMethod.Get)
|
||||
|
@ -1,8 +1,10 @@
|
||||
package de.steamwar.routes
|
||||
|
||||
import de.steamwar.ResponseError
|
||||
import de.steamwar.sql.SQLWrapperImpl
|
||||
import de.steamwar.sql.SchematicType
|
||||
import de.steamwar.sql.SteamwarUser
|
||||
import de.steamwar.sql.loadSchematicTypes
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
@ -20,7 +22,9 @@ data class ResponseUser(val id: Int, val name: String, val uuid: String)
|
||||
fun Routing.configureDataRoutes() {
|
||||
route("/data") {
|
||||
get("/schematicTypes") {
|
||||
call.respond(SchematicType.values().filter { !it.check() }.map { ResponseSchematicType(it.name(), it.toDB()) })
|
||||
val types = mutableListOf<SchematicType>()
|
||||
loadSchematicTypes(types, mutableMapOf())
|
||||
call.respond(types.filter { !it.check() }.map { ResponseSchematicType(it.name(), it.toDB()) })
|
||||
}
|
||||
get("/gamemodes") {
|
||||
call.respond(File("/configs/GameModes/").listFiles().filter { it.name.endsWith(".yml") && !it.name.endsWith(".kits.yml") }.map { it.nameWithoutExtension })
|
||||
|
@ -42,7 +42,8 @@ fun Routing.configureEventFightRoutes() {
|
||||
val eventFight = EventFight.create(fight.event, Timestamp.from(Instant.ofEpochMilli(fight.start)), fight.spielmodus, fight.map, fight.blueTeam, fight.redTeam)
|
||||
call.respond(HttpStatusCode.Created, ResponseEventFight(eventFight))
|
||||
}
|
||||
put("/{fight}") {
|
||||
route("/{fight}") {
|
||||
put {
|
||||
val fightId = call.parameters["fight"]?.toIntOrNull()
|
||||
if (fightId == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid fight ID"))
|
||||
@ -79,5 +80,21 @@ fun Routing.configureEventFightRoutes() {
|
||||
fight.update()
|
||||
call.respond(HttpStatusCode.OK, ResponseEventFight(fight))
|
||||
}
|
||||
delete {
|
||||
val fightId = call.parameters["fight"]?.toIntOrNull()
|
||||
if (fightId == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid fight ID"))
|
||||
return@delete
|
||||
}
|
||||
val fight = EventFight.get(fightId)
|
||||
if (fight == null) {
|
||||
call.respond(HttpStatusCode.NotFound, ResponseError("Fight not found"))
|
||||
return@delete
|
||||
}
|
||||
fight.delete()
|
||||
call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -5,8 +5,7 @@ import java.io.File
|
||||
import java.util.*
|
||||
import java.util.stream.Collectors
|
||||
|
||||
class SQLWrapperImpl: SQLWrapper {
|
||||
override fun loadSchemTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) {
|
||||
fun loadSchematicTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) {
|
||||
val folder = File("/configs/GameModes")
|
||||
if (folder.exists()) {
|
||||
for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") })
|
||||
@ -34,9 +33,11 @@ class SQLWrapperImpl: SQLWrapper {
|
||||
tmpFromDB[type.lowercase(Locale.getDefault())] = current
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SQLWrapperImpl: SQLWrapper {
|
||||
override fun loadSchemTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) = loadSchematicTypes(tmpTypes, tmpFromDB)
|
||||
|
||||
override fun additionalExceptionMetadata(builder: StringBuilder) {
|
||||
builder.append("EventAPI")
|
||||
}
|
||||
|
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren