Browse Source

[FIX] add check if player exists

Adrien Carteron 2 years ago
parent
commit
c956e6a653
1 changed files with 2 additions and 1 deletions
  1. 2 1
      src/main/kotlin/re/chasam/routes/PlayersRoutes.kt

+ 2 - 1
src/main/kotlin/re/chasam/routes/PlayersRoutes.kt

@@ -33,11 +33,12 @@ fun Route.playersRouting() {
         post {
         post {
             val player = call.receive<Player>()
             val player = call.receive<Player>()
             println("post $player")
             println("post $player")
-            tournamentImpl.addOrUpdate(player)
+            tournamentImpl.addOrUpdate(Player(player.name))
             call.respondText("player stored correctly", status = HttpStatusCode.Created)
             call.respondText("player stored correctly", status = HttpStatusCode.Created)
         }
         }
         patch("{id?}") {
         patch("{id?}") {
             val id = call.parameters["id"] ?: return@patch call.respondText("Bad Request", status = HttpStatusCode.BadRequest)
             val id = call.parameters["id"] ?: return@patch call.respondText("Bad Request", status = HttpStatusCode.BadRequest)
+            tournamentImpl.getPlayer(id) ?: return@patch call.respondText("No player found", status = HttpStatusCode.NotFound)
             val player = call.receive<Player>()
             val player = call.receive<Player>()
             println("post $id $player")
             println("post $id $player")
             tournamentImpl.addOrUpdate(id, player.score)
             tournamentImpl.addOrUpdate(id, player.score)