Train-Ticket-Backend

This RESTful API allows administrators to manage train bookings. It handles stations, trains, users, and bookings, enabling functionalities like creating trains with routes, booking seats, and user management.

MIT License

Stars
0
Committers
2

Train Ticket Booking System

Welcome to the Train Ticket Booking System. This application allows administrators to manage users, stations, trains, and bookings through a RESTful API.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/venkateshramkumarg/ecommerce_backend.git
    cd TrainTicket
    
  2. Install dependencies:

    npm install
    
  3. Set up the database using Prisma:

    npx prisma migrate dev
    
  4. Start the application:

    npm start
    

Usage

The application runs on http://localhost:3000/api. You can use tools like Postman or curl to interact with the API.

API Endpoints

Admin

  • Create Admin

    POST /api/admin/create/admin/new
    

    Request Body:

    {
      "user_name": "admin_name",
      "password": "password",
      "email": "[email protected]"
    }
    
  • Delete Admin

    DELETE /api/admin/delete/admin/:name
    
  • Update Admin

    PUT /api/admin/update/admin/:name
    

    Request Body:

    {
      "password": "new_password",
      "email": "[email protected]"
    }
    

Stations

  • Create Station

    POST /api/stations/create/station/new
    

    Request Body:

    {
      "user_name": "admin_name",
      "stationId": "station_id",
      "stationName": "station_name"
    }
    
  • Delete Station

    DELETE /api/stations/delete/station/:id
    
  • Get Station by ID

    GET /api/stations/stations/:id
    

Trains

  • Create Train

    POST /api/trains/create/train/new
    

    Request Body:

    {
      "user_name": "admin_name",
      "trainNo": "train_number",
      "trainName": "train_name",
      "noOfSeatsAvailable": "number_of_seats",
      "departureDate": "departure_date",
      "stationIds": ["station_id1", "station_id2"]
    }
    
  • Delete Train

    DELETE /api/trains/delete/train/:number
    

Users

  • Create User

    POST /api/users/create/user/new
    

    Request Body:

    {
      "user_name": "user_name",
      "password": "password",
      "email": "[email protected]"
    }
    
  • Delete User

    DELETE /api/users/delete/user/:name
    
  • Update User

    PUT /api/users/update/user/:name
    

    Request Body:

    {
      "password": "new_password",
      "email": "[email protected]"
    }
    

Bookings

  • Create Booking

    POST /api/bookings/create/booking/new
    

    Request Body:

    {
      "user_name": "user_name",
      "trainNo": "train_number",
      "seatNo": "seat_number"
    }
    
  • Delete Booking

    DELETE /api/bookings/delete/booking/:id
    

Environment Variables

Create a .env file in the root directory and add the following environment variables:

Related Projects