Skip to content

Commit

Permalink
✨ Add bet list api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Nlkomaru committed Jul 19, 2024
1 parent 64c37f5 commit 5591ca1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/dev/nikomaru/raceassist/files/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ object Config : KoinComponent {

val discordWebHook = DiscordWebHook(arrayListOf(), arrayListOf(), arrayListOf(), arrayListOf(), arrayListOf())
val recordHorse = RecordHorse(13.5, 3.8)
val webAPI = WebAPI(8080, null, null, arrayListOf(), null)
val configData =
ConfigData(VERSION, 40, 200, discordWebHook, recordHorse, null, 600000, null)
ConfigData(VERSION, 40, 200, discordWebHook, recordHorse, webAPI, 600000, null)

val string = json.encodeToString(configData)

Expand Down
13 changes: 7 additions & 6 deletions src/main/kotlin/dev/nikomaru/raceassist/files/ConfigData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ data class DiscordWebHook(
data class RecordHorse(val minSpeed: Double, val minJump: Double)


@Serializable
data class SpreadSheet(val port: Int, val sheetName: ArrayList<String>)

@Serializable
data class WebAPI(
val port: Int,
val sslPort: Int,
val sslSetting: SslSetting,
val sslSetting: SslSetting?,
val jwtConfig: JWTConfig?,
val recordUrl: ArrayList<RecordLog>,
val webPage: String? = null
Expand All @@ -61,7 +57,12 @@ data class WebAPI(
data class RecordLog(val url: String, val name: String, val password: String)

@Serializable
data class SslSetting(val keyAlias: String, val keyStorePassword: String, val privateKeyPassword: String)
data class SslSetting(
val sslPort: Int,
val keyAlias: String,
val keyStorePassword: String,
val privateKeyPassword: String
)

@Serializable
data class MySQL(val url: String, val username: String, val password: String)
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/dev/nikomaru/raceassist/web/api/BetRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ object BetRouter {
}
return@post call.respond(hashMapOf("data" to BetPushResponse(error, responseUniqueIdArray, paymentSum)))
}
get("/list/{raceId}") {
val raceId = call.parameters["raceId"] ?: return@get call.respondText(
"Missing id",
status = HttpStatusCode.BadRequest
)

val principal = call.principal<JWTPrincipal>() ?: return@get call.respondText(
"Missing or invalid jwt token",
status = HttpStatusCode.Unauthorized
)
val player = principal.payload.getClaim("uuid").asString().toUUID().toOfflinePlayer()

if (RaceAssist.api.getRaceManager(raceId)?.existStaff(player) != true) return@get call.respondText(
"You do not have permission to view this data",
status = HttpStatusCode.Forbidden
)

val list = BetUtils.listBetData(raceId)
call.respond(hashMapOf("data" to list))
}
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/main/kotlin/dev/nikomaru/raceassist/web/api/WebAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,23 @@ object WebAPI : KoinComponent {

fun settingServer() {
val keyStoreFile = plugin.dataFolder.resolve("keystore.jks")
val keystore =
KeyStore.getInstance(keyStoreFile, Config.config.webAPI!!.sslSetting.keyStorePassword.toCharArray())


val environment = applicationEngineEnvironment {
connector {
port = Config.config.webAPI!!.port
}
sslConnector(keyStore = keystore,
keyAlias = Config.config.webAPI!!.sslSetting.keyAlias,
keyStorePassword = { Config.config.webAPI!!.sslSetting.keyStorePassword.toCharArray() },
privateKeyPassword = { Config.config.webAPI!!.sslSetting.privateKeyPassword.toCharArray() }) {
port = Config.config.webAPI!!.sslPort
keyStorePath = keyStoreFile
val sslSetting = Config.config.webAPI!!.sslSetting
if (sslSetting != null) {
val keystore =
KeyStore.getInstance(keyStoreFile, sslSetting.keyStorePassword.toCharArray())
sslConnector(keyStore = keystore,
keyAlias = sslSetting.keyAlias,
keyStorePassword = { sslSetting.keyStorePassword.toCharArray() },
privateKeyPassword = { sslSetting.privateKeyPassword.toCharArray() }) {
port = sslSetting.sslPort
keyStorePath = keyStoreFile
}
}
module(Application::module)
}
Expand Down

0 comments on commit 5591ca1

Please sign in to comment.