Lottery Application

This is a Spring Boot application for a lottery system where guests can select a pre-populated lottery ticket, register their details, and participate in a lottery draw. The application calculates winnings based on predefined rules.

Table of Contents

Features

  • Registration of guest details, including name and mobile number.
  • Dynamic lottery draw with random number and letter generation.
  • Calculation of winnings based on matching numbers and letters.
  • Storage of participant details for future reference.

Technologies Used

  • Spring Boot
  • Java
  • Maven
  • H2 Database

API Endpoints

1. Register Guest with Ticket

  • Endpoint: POST /api/tickets
  • Description: Registers a guest with their selected ticket and calculates the winnings.

Sample Request Body

{
    "name": "YSanj98",
    "mobile": "0771234567",
    "ticket": "4 6 2 7 U"
}

Sample Response

  • Success (200 OK):
{
    "guestId": 1,
    "name": "YSanj98",
    "mobile": "0771234567",
    "ticket": "4 6 2 7 U",
    "amountWon": 200.0,
    "percentageWon": 20,
}

2. Retrieve All Lotteries

  • Endpoint: GET /api/lotteries
  • Description: Retrieves all lottery draws and guest details.

Sample Response

  • Success (200 OK):
[
    {
        "lotteryId": 1,
        "lotterySequence": "4 6 2 7 U",
        "drawnSequence": "2 4 6 7 X",
        "jackpot": 1000.0,
        "guests": [
            {
                "guestId": 1,
                "name": "YSanj98",
                "mobile": "0771234567",
                "ticket": "4 6 2 7 U",
                "amountWon": 200.0,
                "percentageWon": 20
            }
        ]
    }
]

Running the Application

  1. Clone the repository:

    git clone https://github.com/YSanj98/lottery-application.git
    cd lottery-application
  2. Build the application using Maven:

    mvn clean install
  3. Run the application:

    mvn spring-boot:run
  4. Access the API at http://localhost:8080/api.