Class RoulettePost

All Implemented Interfaces:
spark.Route

public class RoulettePost extends PostRoute
Handles the "/games/roulette" POST request, processing user bets, updating the user's balance, and registering a new roulette game result. Redirects the user to the replay page with the game results.
  • Field Details

    • logger

      private org.slf4j.Logger logger
      The logger for the RoulettePost class.
    • rouletteItems

      private Map<Integer,String> rouletteItems
      A map of roulette numbers and their corresponding colors.
  • Constructor Details

    • RoulettePost

      public RoulettePost(App app)
      Initializes the route handler with the app instance and sets the route path. Also initializes the roulette items map with predefined colors for each number.
      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 roulette game. It validates the user's balance, simulates the roulette spin, stores the result in the database, and updates the user's balance. Finally, it redirects the user to the replay page with the game result.
      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.