Skip to content

Commit

Permalink
Add route to fetch match
Browse files Browse the repository at this point in the history
  • Loading branch information
jellz committed Mar 7, 2023
1 parent 4af5911 commit 5ab8656
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import network.warzone.api.http.broadcast.broadcastRoutes
import network.warzone.api.http.leaderboard.leaderboardRoutes
import network.warzone.api.http.level.levelRoutes
import network.warzone.api.http.map.mapRoutes
import network.warzone.api.http.match.matchRoutes
import network.warzone.api.http.perks.perkRoutes
import network.warzone.api.http.punishment.punishmentRoutes
import network.warzone.api.http.rank.rankRoutes
Expand Down Expand Up @@ -115,6 +116,7 @@ class Server {

statusRoutes()
playerRoutes()
matchRoutes()
rankRoutes()
tagRoutes()
mapRoutes()
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/http/Exceptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class MapMissingException :
class PunishmentMissingException :
ApiException(HttpStatusCode.NotFound, ApiExceptionType.PUNISHMENT_MISSING, "The punishment does not exist")

class MatchMissingException : ApiException(HttpStatusCode.NotFound, ApiExceptionType.MATCH_MISSING, "The match does not exist")

class NoteMissingException :
ApiException(HttpStatusCode.NotFound, ApiExceptionType.NOTE_MISSING, "The note does not exist")

Expand Down Expand Up @@ -98,6 +100,7 @@ enum class ApiExceptionType {
TAG_ALREADY_PRESENT,
TAG_NOT_PRESENT,
MAP_MISSING,
MATCH_MISSING,
PUNISHMENT_MISSING,
NOTE_MISSING
}
25 changes: 25 additions & 0 deletions src/main/kotlin/http/match/MatchRoutes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package network.warzone.api.http.match

import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
import network.warzone.api.database.MatchCache
import network.warzone.api.database.models.Match
import network.warzone.api.http.MatchMissingException
import network.warzone.api.http.ValidationException

fun Route.matches() {
get("/{matchId}") {
val matchId = call.parameters["matchId"]?.lowercase() ?: throw ValidationException()
val match: Match = MatchCache.get(matchId) ?: throw MatchMissingException()
call.respond(match)
}
}

fun Application.matchRoutes() {
routing {
route("/mc/matches") {
matches()
}
}
}

0 comments on commit 5ab8656

Please sign in to comment.