mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-04-26 11:28:31 -05:00
Finish v3 status endpoints
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package org.dreamexposure.discal.core.`object`.rest
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Serializable
|
||||
data class GenericResponse(
|
||||
val message: String,
|
||||
|
||||
) {
|
||||
|
||||
fun asMono(): Mono<GenericResponse> = Mono.just(this)
|
||||
}
|
||||
+15
-3
@@ -1,11 +1,12 @@
|
||||
package org.dreamexposure.discal.server.endpoints.v3
|
||||
|
||||
import org.dreamexposure.discal.core.`object`.network.discal.NetworkData
|
||||
import org.dreamexposure.discal.core.`object`.rest.GenericResponse
|
||||
import org.dreamexposure.discal.core.`object`.rest.HeartbeatRequest
|
||||
import org.dreamexposure.discal.core.`object`.rest.HeartbeatType
|
||||
import org.dreamexposure.discal.core.annotations.Authentication
|
||||
import org.dreamexposure.discal.server.network.discal.NetworkManager
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@RestController
|
||||
@@ -17,4 +18,15 @@ class StatusEndpoint(val networkManager: NetworkManager) {
|
||||
fun get(): Mono<NetworkData> {
|
||||
return Mono.just(networkManager.getStatus())
|
||||
}
|
||||
|
||||
@Authentication(access = Authentication.AccessLevel.ADMIN)
|
||||
@PostMapping("status", produces = ["application/json"])
|
||||
fun post(@RequestBody body: HeartbeatRequest): Mono<GenericResponse> {
|
||||
when (body.type) {
|
||||
HeartbeatType.BOT -> networkManager.handleBot(body.botInstanceData!!)
|
||||
HeartbeatType.WEBSITE -> networkManager.handleWebsite(body.instanceData!!)
|
||||
HeartbeatType.CAM -> networkManager.handleCam(body.instanceData!!)
|
||||
}
|
||||
return GenericResponse("Success!").asMono()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@ package org.dreamexposure.discal.server.utils
|
||||
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Deprecated(message = "Use GenericResponse data class")
|
||||
internal fun responseMessage(str: String) = Mono.just("""{"message": "$str"}""")
|
||||
|
||||
Reference in New Issue
Block a user