Skip to content

sandeepbarnwal/train-ticketing-system

Repository files navigation

Train ticket booking System

A Spring Boot based backend application for booking train tickets.

Features

  • Book a train ticket
  • Cancel a train ticket
  • View receipt/ticket details
  • View passengers and seat arrangements in a given section of a train
  • Modify passenger's seat on request

Languages, tools and frameworks

  • Java 17
  • Spring Boot 3.3.0
  • MySQl/H2

Prerequisites

  • Java 17
  • Gradle (wrapped with project)
  • MySQL/H2 (H2 is embedded)

Getting started

1. Build the project

     ./gradle clean build

2. Run the application

     java  -jar build/libs/tms-0.0.1-SNAPSHOT.jar --server.port=8080

3. Check the endpoints

a. Check below mentioned endpoints (Refer curl_commands.md for example)

4. Database information

a. This application uses an H2 database by default and populates seed data on startup.

API Endpoints

Book Ticket

  • URL: /api/bookings/
  • Method: POST
  • Description: create a ticket booking.
  • Request Body:
    {
    "email": "sandeep.barnwal@outlook.com",
    "firstName": "Sandeep",
    "lastName": "Barnwal",
    "price": 20.0,
    "trainCode": "fln-expr",
    "fromStation": "London",
    "toStation": "France",
    "travelDate": "2024-07-17",
    "passengers": [
      {
        "firstName": "Sandeep",
        "lastName": "Kumar",
        "age": 30
      }
    ]

}

  • Response Body:
    {
      "id": 3,
      "bookingTime": "2024-07-18T00:26:38.47342",
      "pricePaid": 20.0,
      "tickets": [
          {
              "id": 3,
              "passengerFirstName": "Sandeep",
              "passengerLastName": "Kumar",
              "departureTime": "2024-07-17T08:30:00",
              "pnr": "9BMQKUX7",
              "trainCode": "fln-expr",
              "sectionName": "fln-A",
              "seatNumber": "A3",
              "startStop": "London",
              "endStop": "France"
          }
      ]
    } 
    

Cancel Ticket

  • URL: /api/bookings/cancel/{pnr}
  • Method: POST
  • Description: cancel a ticket booking.
  • Request Body:
  • Response Body:
    {
    "pnr" : "7SBDMTI5",
    "status" : "cancelled"
    }
    
    

View Receipt Details for a single ticket

  • URL: /api/tickets/{pnr}
  • Method: POST
  • Description: create a ticket booking.
  • Request Body:
  • Response Body:
    {
      "id": 2,
      "passengerFirstName": "Sandeep",
      "passengerLastName": "Kumar",
      "departureTime": "2024-07-17T08:30:00",
      "pnr": "7SBDMTI5",
      "trainCode": "fln-expr",
      "sectionName": "fln-A",
      "seatNumber": "A2",
      "startStop": "London",
      "endStop": "France"
    }
    
    

View Passengers by Section

  • URL: /api/sections/view/{sectionId}
  • Method: POST
  • Description: View passengers and seats arrangement in a given section.
  • Request Body:
  • Response Body:
    [
      {
          "seatNumber": "A1",
          "passengerName": ""
      },
      {
          "seatNumber": "A2",
          "passengerName": "Sandeep Kumar"
      },
      {
          "seatNumber": "A3",
          "passengerName": "Sandeep Kumar"
      }
    ]
    
    

Modify seats of a passenger

  • URL: /api/tickets/{pnr}/seat/{newSeatNumber}
  • Method: POST
  • Description: Changes seat of a passenger if available.
  • Request Body:
  • Response Body:
    {
      "id": 1,
      "passengerFirstName": "Sandeep",
      "passengerLastName": "Kumar",
      "departureTime": "2024-07-17T08:30:00",
      "pnr": "5SAIKCF2",
      "trainCode": "fln-expr",
      "sectionName": "fln-A",
      "seatNumber": "A1",
      "startStop": "London",
      "endStop": "France"
    }
    
    

TODO

  • ** add test cases
  • ** add schema.sql for seed data
  • ** Integrate swagger for documentation

Author

  • Sandeep Kumar

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages