This project implements a RESTful API for managing train tickets, allowing users to purchase tickets, view receipts, manage seats, and more.
- Java
- Spring Boot
- Maven
- Java 8 or higher
- Maven
-
Clone the repository:
git clone https://github.com/ashwinc17/trainticketservice.git
-
Navigate to the project directory:
cd trainticketservice
-
Build the project using Maven:
mvn clean install
-
Run the application:
java -jar target/trainticketservice.jar
-
The application should now be running on
http://localhost:8080
.
POST /tickets/purchase
: Purchase a train ticket.GET /tickets/receipt/{email}
: Get the receipt for a user.GET /tickets/users/{section}
: Get users and their seats in a specific section.DELETE /tickets/remove/{email}
: Remove a user from the train.PUT /tickets/modify-seat
: Modify a user's seat.
To purchase a ticket, send a POST request to /tickets/purchase
with the user details and ticket information in the request body.
Example:
curl -X POST -H "Content-Type: application/json" -d "{\"firstName\": \"John\", \"lastName\": \"Doe\", \"email\": \"john.doe@example.com\"}" "http://localhost:8080/tickets/purchase?from=London&to=France&price=20.0"
To view a receipt, send a GET request to /tickets/receipt/{email}
with the user's email address as a path variable.
Example:
curl -X GET http://localhost:8080/tickets/receipt/john.doe@example.com
To modify a user's seat, send a PUT request to /tickets/modify-seat
with the user's email address and the new seat number as query parameters.
Example:
curl -X PUT "http://localhost:8080/tickets/modify-seat?email=john.doe@example.com&newSeat=B5"
To remove a user from the train, send a DELETE request to /tickets/remove/{email}
with the user's email address as a path variable.
Example:
curl -X DELETE http://localhost:8080/tickets/remove/john.doe@example.com