# Book buss API Doc
## Introduction
The online bus booking website API allows users to search for and book bus tickets through a third-party website or application. The API provides a simple and consistent interface for accessing information about available bus routes, schedules, and prices, as well as the ability to reserve and purchase tickets.
## Endpoints
The following is a list of the available endpoints for the online bus booking website API:
### Get bus end point
```
GET /buses
```
##### Function
this endpoint allows you to search between any onboarding station and destination station on a specific date
It will have query parameters below
| parameter | type |
| ----------- |:------ |
| origin | string |
| destination | string |
| date | string(YYYY-MM--DD) |
request will look like as below
```javascript
# Search for routes between Rourkela and Ranchi on December 10th
GET /buses?origin=Rourkela&destination=Ranchi&date=2022-12-10
```
##### status codes
| Status code | Response Type |
| -------- | -------- |
| 200 | JSON |
| 400 | ERROR |
##### expected response returned json
```json
[{
"_id": "6789021877892",
"buss_name": "Pihu",
"Type": "AC",
"priceOfEachSeat": 120,
"route":[{
"station": "Rourkela"
"Departure time": "16:00"
},{
"station": "Ranchi"
"departure time": "18:00"
},{
"station": "Rourkela"
"departure time": "23:00"
}],
"rating" : "3.1",
"Total_seats": 10,
"Available_seats": 5,
"Seat_matrix": [{
"seat_number": 1,
"status": "Confirm"
},{
"seat_number": 2,
"status": "available"
},
.
.
..
]
},
.
.
..
]
```
##### error
```
status code: 400
```
##### error messge
```
No buses are available in this route
```
### Discount coupon check
```htmlembedded!
POST /buss/coupon
```
##### Function
This is to confirm the originality of the coupon code added at the fronted.
| parameter | type |
| ----------- |:------ |
| userID | string |
| bussID | string |
| code | String |
##### Expected response
```
Status code : 200
```
##### Success Message
```
message: Applicable
```
##### Error
```
Status code : 400
```
##### Error Message
```
message: Not Applicable
```
### Book Ticket
```htmlembedded!
POST /buss/book
```
##### Function
This is a payload to update the bus status and book the ticket. Moreover, it takes all the details like seat coupon codes etc and checks everything at the backend, for example, it checks the availability of seats and computes the total valid amt at the backend to match with the received amt to prevent scams.
Below are the payloads.
| parameter | type |
| ----------- |:------ |
| userID | string |
| bussID | string |
| seats | [Number] |
| date | string(YYYY-MM--DD) |
| origin | string |
| destination | string |
| couponCode | string |
| TotalAMT | Number |
##### Success code
```
Status code : 200
```
##### Success Message
```
message: Ticket Booked Successfully
```
##### Error Code
```
Status code : 400
```
##### Error Message
```
message: was not able to book the ticket.
```
### GET TRANSACTIONS
```htmlembedded!
GET /buss/transaction?userID={logedinuserID}
```
This is to fetch all the details of the previous transactions by the user.
##### Expected response
| Status code | Response Type |
| -------- | -------- |
| 200 | JSON |
##### returned json
```json
[{
"_id": "6789021877892",
"userID": "212132432423",
"bussID": "124235432342",
"seats": [3, 7, 11, 14],
"origin" : "Rourkela",
"destination": "Ranchi",
"Total Amt": 120.32
},
.
.
..
]
```
##### Error Code
```json
Status: 400
```
##### Error Message
```
no transactions found
```
### Register User
##### Function
To register a user
```javascript
POST auth/register
```
##### Payload
| parameter | type |
| ----------- |:------ |
| email | string |
| password | string |
##### Expected Success Response
```
status code: 200
```
##### Success Message
```
message: "User Added"
```
##### Error Status Code
```
Status Code: 400
```
##### Error Message
```
message: was not able to register new user
```
### Login
##### Function
To send a request to the server to confirm user password and set up a jwt token in the server
```javascript
POST auth/login
```
##### Payload
| parameter | type |
| ----------- |:------ |
| email | string |
| password | string |
##### Expected Success Response
```
Status Code: 200
```
##### Success Message
```
message: "User is logged in"
```
##### Response JSON
```json
{
"_id": "{UserID}",
"email": "{User Email}"
}
```
##### Error Status Code
```
Status Code: 400
```
##### Error Message
```
message: please use valid credentials
```
### Admin add buss
##### Function
To add new buss to the portal
```javascript
POST /admin/add
```
```jsonld!
Expected payload from the admin
{
"_id": "6789021877892",
"buss_name": "Pihu",
"Type": "AC",
"priceOfEachSeat": 120,
"route":[{
"station": "Rourkela"
"Departure time": "16:00"
},{
"station": "Ranchi"
"departure time": "18:00"
},{
"station": "Rourkela"
"departure time": "23:00"
}],
"Total_seats": 10
}
```
##### Expected Status Code
```
status Code: 200
```
##### Message
```
message: "Buss Added"
```
##### Error Status Code
```
Status Code: 400
```
##### Message for Error
```
Messafe: bus was not added.
```
### Admin edit buss
##### Function
To edit details of a buss.
```javascript
POST /admin/edit
```
```jsonld!
Expected payload from the admin
{
"_id": "6789021877892",
"{Field to be edited}": "{New value}",
"{Field to be edited}": "{New value}",
.
.
"{Field to be edited}": "{New value}",
.
}
```
##### Expected Status Code
```
Status Code: 200
```
##### Success Message
```
message: "Buss data edited"
```
##### Error Code
```
Status Code: 400
```
##### Error Message
```
message: not able to edit the details.
```
### Admin view buss
##### Function
To provide the admin with the current details of the buss including the status of seats etc.
```javascript
GET /admin/buss?bussId=13421
```
##### Expected Response
```
Status Code: 200
```
```jsonld!
{
"_id": "6789021877892",
"buss_name": "Pihu",
"Type": "AC",
"priceOfEachSeat": 120,
"route":[{
"station": "Rourkela"
"Departure time": "16:00"
},{
"station": "Ranchi"
"departure time": "18:00"
},{
"station": "Rourkela"
"departure time": "23:00"
}],
"rating" : "3.1",
"Total_seats": 10,
"Available_seats": 5,
"Seat_matrix": [{
"seatNumber": 1,
"status": "confirm"
},{
"seatNumber": 2,
"status": "available"
},
.
.
..
]
}
```
##### Error Status Code
```
Status Code: 400
```
##### Error Message
```
message: No busses found.
```