Class HorsesPost

All Implemented Interfaces:
spark.Route

public class HorsesPost extends PostRoute
Handles the "/games/horses" POST request, managing user bets, updating the user's balance, and registering a new horse racing game. It also redirects to the replay page with the game results.
  • Field Details

    • logger

      private org.slf4j.Logger logger
      The logger used to log the user's horse racing games.
  • Constructor Details

    • HorsesPost

      public HorsesPost(App app)
      Initializes the route handler with the app instance and sets the route path.
      Parameters:
      app - The main application instance.
  • Method Details

    • handlePost

      public void handlePost(spark.Request request, spark.Response response) throws SQLException
      Handles the POST request for the horse racing game. It validates user balance, generates random race data according to the database schema, stores the result in the database, and updates the user's balance based on the outcome of the game. Redirects the user to the replay page with the race results.
      Specified by:
      handlePost in class PostRoute
      Parameters:
      request - The HTTP request containing the game parameters.
      response - The HTTP response used to redirect the user.
      Throws:
      SQLException - If any errors occur during the request handling.