A Laravel application for booking seats on trips.
The Laravel Booking System is an application that allows users to book seats for specific trips. This README provides documentation for the bookSeat
method, which handles seat bookings in the system.
To get started with this Laravel project, follow these steps:
-
Clone the Repository: Clone this repository to your local machine using Git:
git clone https://github.com/AbdallahMostafa/bus-booking-system
-
Install Dependencies: Navigate to the project's root directory and install the Build the containers and their Depedenecies:
cd bus-booking-system bash init.sh
-
Create Environment File: Copy the
.env.example
file to.env
and update it with your configuration settings such as database connection, app key, and other environment-specific variables:cp .env.example .env
-
Generate Application Key (Docker): If you are running the Laravel project within a Docker container, you can generate the application key by executing the following command within the container:
docker exec -it laravel php artisan key:generate
This endpoint allows users to register a new account.
- Method: POST
- Endpoint:
/api/register
- Headers:
Content-Type
(string):application/json
The request body should contain JSON data with the following fields:
name
(string, required): The name of the user.email
(string, required): The email address of the user.password
(string, required): The user's password.
Example Request:
POST /api/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}
This endpoint allows registered users to log in and obtain an authentication token.
- Method: POST
- Endpoint:
/api/login
- Headers:
Content-Type
(string):application/json
The request body should contain JSON data with the following fields:
email
(string, required): The email address of the user.password
(string, required): The user's password.
Example Request:
POST /api/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "password123"
}
The "Available Seats" API provides information about the available seats on a specific trip between two stations. It allows you to check which seats are available for booking.
- URL:
/api/available-seats
- HTTP Method: GET
- Headers:
Authorization
(string): A Bearer token for authentication.
departure_location_id
(string, required): The name of the departure station.arrival_location_id
(string, required): The name of the arrival station.
- HTTP Status Code: 200 (OK)
- Content Type: JSON
If there are available seats for booking, the API will respond with a JSON object containing an array of available seat numbers.
Example:
{
"available_seats": [1, 2, 3, 4, 5]
}
The bookSeat
method is used to book a seat for a user on a specific trip.
-
Method: POST
-
Endpoint:
/api/book-seat
-
Headers:
Authorization
(string): A Bearer token for authentication.
-
Parameters:
departure_location_id
(string): The name of the departure station.arrival_location_id
(string): The name of the arrival station.seat_id
(int): The ID of the seat to be booked.
- Status Code: 200 OK
- Data:
Booked Successfully
(object): Details of the reservation.
-
Status Code: 401 Unauthorized
-
Data:
error
(string): Error message indicating that the token is invalid.
-
Status Code: 422 Unprocessable Entity
-
Data:
message
(string): Error message indicating that the seat is already booked or unavailable.
-
Status Code: 500 Internal Server Error
-
Data:
message
(string): Error message indicating that an error occurred while booking the seat.
Content-Type: application/json
Authorization: Bearer your-auth-token
{
"departure_location_id": "Cairo",
"arrival_location_id": "Asyut",
"seat_id": 1
}