Coder Social home page Coder Social logo

irctc-api's Introduction

Train System Application

This is a Node.js application for managing a train system. It provides functionalities for user authentication, signing up, logging in, adding trains, checking seat availability, booking seats, and fetching booking details.

Prerequisites

  • Node.js installed on your machine
  • MySQL server running locally

Installation

  1. Clone the repository to your local machine:

  2. Navigate to the project directory:

  3. Install dependencies:

    npm install
  4. Set up your MySQL database:

    • Run the MySQL server.
    • Execute the provided SQL commands in your MySQL database to create the necessary tables. You can find the SQL commands in the comments at the end of app.js file.
  5. Configure the MySQL connection:

    • Open app.js file.
    • Update the MySQL connection parameters (host, user, password, database) according to your MySQL setup.

Usage

  1. Start the server:

    npm start
  2. The server will start running on port 3000 by default.

  3. You can access the endpoints using a tool like Postman or by sending HTTP requests programmatically.

Endpoints

  • GET /: Welcome message indicating the successful running of the server.
  • POST /signup: Endpoint for user signup. Requires username, password, and isAdmin (boolean) fields in the request body.
  • POST /login: Endpoint for user login. Requires username and password fields in the request body.
  • POST /trains: Endpoint for adding a new train. Requires source, destination, and userId fields in the request body.
  • GET /trains: Endpoint for retrieving available trains based on source and destination query parameters.
  • POST /book: Endpoint for booking a seat on a train. Requires userId and trainId fields in the request body.
  • GET /bookings/:userId: Endpoint for fetching booking details for a specific user identified by userId parameter.

Middleware

  • authenticateUser: Middleware function to ensure user authentication for protected routes. It checks if a valid userId is present in the request body.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.

Tests

Tests are not included in this version of the application. However, you can write your own tests using testing frameworks like Mocha and Chai. Feel free to contribute tests if you find it necessary.

License

This project is licensed under the MIT License - see the LICENSE file for details.

irctc-api's People

Contributors

anuraaga-12 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.