This project provides a set of microservices related to hotel management, built using Flask, with services for user management, destination management, and authentication. The services are containerized using Docker for easy deployment and scalability.
git clone https://github.com/aa-nadim/hotel-api-flask.git
cd hotel-api-flask
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python -m venv .venv
source .venv/Scripts/activate
pip install -r requirements.txt
deactivate
- Docker: Ensure that Docker and Docker Compose are installed on your machine.
To build the Docker images for all services and start the containers, run:
sudo docker-compose up -d --build
docker-compose down
Run the user service on port 5001:
python user_service/app.py
Run the destination service on port 5002:
python destination_service/app.py
Run the authentication service on port 5003:
python auth_service/app.py
-
User Service:
- Run on: http://127.0.0.1:5001/apidocs/
-
Destination Service:
- Run on: http://127.0.0.1:5002/apidocs/
-
Auth Service:
- Run on: http://127.0.0.1:5003/apidocs/
Use Swagger UI to test the endpoints, review request/response formats, and explore available features.
Run the unit tests for each service individually:
pytest user_service/__tests__/test_user_service.py
pytest user_service --cov=.
pytest destination_service/__tests__/test_destination_service.py
pytest destination_service --cov=.
pytest auth_service/__tests__/test_auth_service.py
pytest auth_service --cov=.
To run all tests and check the combined coverage:
pytest --cov=user_service --cov=destination_service --cov=auth_service --cov-report=term --cov-report=html
Open the generated htmlcov/index.html
for detailed coverage reports.
- URL:
/register
- Method:
POST
- Description: Register a new user with the required details.
- Request Body:
{ "email": "user@example.com", "password": "Password123", "name": "John Doe", "role": "User" }
- Responses:
201
: User registered successfully400
: Missing fields or invalid input
- URL:
/login
- Method:
POST
- Description: Authenticate a user and provide an access token.
- Request Body:
{ "email": "user@example.com", "password": "Password123" }
- Responses:
200
: Login successful with JWT token400
: Missing email or password401
: Invalid credentials
- URL:
/profile
- Method:
GET
- Description: View the profile of the logged-in user.
- Authentication: JWT token is required (Authorization header with "Bearer {token}").
- Responses:
200
: User profile data (email, role)401
: Unauthorized (no token provided)
- URL:
/addDestinations
- Method:
POST
- Description: Add a new destination (Admin only).
- Authentication: JWT token required (Admin role).
- Request Body:
{ "name": "Bali", "description": "A tropical paradise", "location": "Indonesia", "price_per_night": 200.5 }
- Responses:
201
: Destination added successfully401
: Unauthorized (Admin access required)400
: Missing fields or invalid data
- URL:
/destinations
- Method:
GET
- Description: Retrieve a list of all destinations.
- Responses:
200
: List of all destinations
- URL:
/destinations/<id>
- Method:
DELETE
- Description: Delete a destination by its ID (Admin only).
- Authentication: JWT token required (Admin role).
- Parameters:
id
: Destination ID (string)
- Responses:
200
: Destination deleted successfully401
: Unauthorized (Admin access required)404
: Destination not found
- URL:
/auth
- Method:
GET
- Description: Get access to destinations with role-based access.
- Authentication: JWT token required (Admin or User role).
- Responses:
200
: Role-based message (for Admin and User roles)401
: Missing or invalid JWT token403
: Role not recognized or unauthorized
400
: Bad Request – Missing required fields or invalid input401
: Unauthorized – Token missing or invalid403
: Forbidden – Insufficient role privileges (Admin required)404
: Not Found – The requested resource was not found422
: Unprocessable Entity – Invalid token format or signature