Quelques mises a jour amusantes

This commit is contained in:
François Pelletier 2024-09-06 19:53:24 -04:00
parent bb95f8f8fd
commit 5d4ea4e85a
14 changed files with 294 additions and 73 deletions

View file

@ -15,11 +15,16 @@ class GameController @Inject()(val controllerComponents: ControllerComponents) e
Ok(views.html.game())
}
def getBricks: Action[AnyContent] = Action {
val source = scala.io.Source.fromFile("conf/bricks.json")
val jsonString = try source.mkString finally source.close()
val bricks = Json.parse(jsonString).as[List[Brick]]
Ok(Json.toJson(bricks))
def getBricks(file: String): Action[AnyContent] = Action {
val filePath = s"conf/$file"
try {
val source = scala.io.Source.fromFile(filePath)
val jsonString = try source.mkString finally source.close()
val bricks = Json.parse(jsonString).as[List[Brick]]
Ok(Json.toJson(bricks))
} catch {
case e: Exception =>
BadRequest(s"Error reading file: ${e.getMessage}")
}
}
}
}