This is a RESTful API for managing travel orders, including user authentication, travel order creation, search with multiple parameters, status updates, mail notification, and more. The API is designed for use by travel agencies and their clients, with full documentation provided below.
In this Laravel API example, we demonstrate the use of multiple Laravel features to build an API, including Routes, Resources, Middlewares, Policies, Eloquent ORM, Enums, Mailables, and more.
- Installation
- Running Locally
- Testing
- Postman Testing
- API Endpoints Documentation
- Filters for Travel Order Search
-
Clone the Repository:
git clone [email protected]:33Piter/travel-agency-api.git cd travel-agency-api
-
Automated Installation (preferred):
- Run the installation script:
chmod +x install.sh ./install.sh
- Optionally, run the script with --skip-tests to skip running tests.
- Manual Installation:
-
Install dependencies:
composer install
-
Copy the example environment configuration:
cp .env.example .env
-
Start Docker containers with Laravel Sail:
./vendor/bin/sail up -d
-
Generate JWT secret:
./vendor/bin/sail artisan jwt:secret --force
-
Run tests (optional):
./vendor/bin/sail artisan test
- Run the Application (it is already running if you follow the installation steps):
-
To start the application, use:
./vendor/bin/sail up -d
-
To stop the application, use:
./vendor/bin/sail down
- Optional Migration and Seeding:
- If you wish to populate the database with some fake users and travel orders, run migrations and seed:
./vendor/bin/sail artisan migrate --seed
By default, the applications runs on localhost port 7001. If you want to change the port, you can do so by editing the APP_PORT variable in the .env file.
The application is covered by multiple tests. To run all tests, use the following command:
- Run all tests:
./vendor/bin/sail artisan test
A Postman collection is included in the repository to simplify testing:
-
Import the Collection: Open Postman, go to "File > Import," and import the collection file located at
docs\Travel Agency API.postman_collection.json
in the repository. -
Base URL: The default base url variable is set to 'http://localhost:7001/api/v1'. Change it if you are running the application on a different port.
-
Authentication:
- Start with the
Register User
orLogin
endpoints to obtain an authentication token. - Add the
Authorization
header with the token for secured endpoints.
- Start with the
Endpoint | HTTP Method | Description | Authentication Required |
---|---|---|---|
/auth/register |
POST | Register a new user. No authentication required for this action. | No |
/auth/login |
POST | Login a user and retrieve the authentication token. | No |
/auth/logout |
GET | Logout the user and invalidate the authentication token. | Yes |
/auth/refresh |
GET | Refresh the authentication token to extend the user's session. | Yes |
/auth/user |
GET | Retrieve the authenticated user's information. | Yes |
/travel-order |
POST | Create a new travel order. Only the authenticated user can create orders. | Yes |
/travel-order/{id} |
GET | Retrieve a specific travel order by ID. This will only return the order if the authenticated user owns it. | Yes |
/travel-order |
GET | Search for travel orders. This will only show travel orders that the authenticated user owns. The results are paginated (10 per page). See all search filters below. | Yes |
/travel-order/{id}?status |
PUT | Update a specific travel order by ID. The user can only update orders they own. | Yes |
/travel-order/notify/{id} |
GET | Notify the user associated with a travel order via email. This action is only permitted if the user owns the travel order. | Yes |
- Departure date range
departure_date_start
: Enter the start of the date range (format: YYYY-MM-DD).
departure_date_end
: Enter the end of the date range (format: YYYY-MM-DD, must be after or equal to departure_date_start
).
- Return date range
return_date_start
: Enter the start of the date range (format: YYYY-MM-DD).
return_date_end
: Enter the end of the date range (format: YYYY-MM-DD, must be after or equal to return_date_start
).
- Date range (both departure and return)
date_range_start
: Enter the start of the date range (format: YYYY-MM-DD).
date_range_end
: Enter the end of the date range (format: YYYY-MM-DD, must be after or equal to date_range_start
).
- Status
status
: Filter by travel order status. It must be one of the following values: 'requested', 'approved' or 'canceled'.
- Destination
destination
: Filter by the destination of the travel order.