2025-06-02 12:04:09 +00:00

116 lines
3.8 KiB
Markdown

# Rental Services API
This is a FastAPI application for managing rental services. It provides endpoints for managing rental items, categories, customers, and rental records.
## Features
- Rental items management (with categories)
- Customer management
- Rental records tracking
- SQLite database with SQLAlchemy ORM
- Alembic for database migrations
- OpenAPI documentation
## API Endpoints
### Health Check
- GET `/health` - Check API health
### Categories
- GET `/api/v1/rentals/categories/` - List all categories
- GET `/api/v1/rentals/categories/{category_id}` - Get category by ID
### Rental Items
- GET `/api/v1/rentals/items/` - List all rental items
- Query params:
- `category_id` - Filter by category
- `available_only` - Filter by availability
- GET `/api/v1/rentals/items/{item_id}` - Get rental item by ID
### Customers
- GET `/api/v1/rentals/customers/` - List all customers
- GET `/api/v1/rentals/customers/{customer_id}` - Get customer by ID
- GET `/api/v1/rentals/customers/email/{email}` - Get customer by email
### Rental Records
- GET `/api/v1/rentals/records/` - List all rental records
- Query params:
- `customer_id` - Filter by customer
- `item_id` - Filter by rental item
- `active_only` - Filter active rentals only
- GET `/api/v1/rentals/records/{record_id}` - Get rental record by ID
## Project Structure
```
├── app/
│ ├── api/
│ │ └── v1/
│ │ ├── endpoints/
│ │ │ └── rentals.py # API endpoints
│ │ └── api.py # API router
│ ├── core/
│ │ └── config.py # Application configuration
│ ├── crud/
│ │ ├── base.py # Base CRUD operations
│ │ ├── crud_category.py # Category CRUD operations
│ │ ├── crud_customer.py # Customer CRUD operations
│ │ ├── crud_rental_item.py # Rental item CRUD operations
│ │ └── crud_rental_record.py # Rental record CRUD operations
│ ├── db/
│ │ └── session.py # Database session
│ ├── models/
│ │ ├── base.py # Base model
│ │ └── rental.py # Database models
│ └── schemas/
│ ├── category.py # Category schemas
│ ├── customer.py # Customer schemas
│ ├── rental_item.py # Rental item schemas
│ └── rental_record.py # Rental record schemas
├── migrations/ # Alembic migrations
│ ├── versions/
│ │ └── 001_initial_schema.py # Initial database schema
│ ├── env.py # Migration environment
│ └── script.py.mako # Migration script template
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Python dependencies
```
## Setup and Running
1. Install dependencies:
```
pip install -r requirements.txt
```
2. Run database migrations:
```
alembic upgrade head
```
3. Start the API server:
```
uvicorn main:app --reload
```
4. Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## Environment Variables
The application uses environment variables for configuration. Create a `.env` file in the root directory with the following variables:
```
PROJECT_NAME=Rental Services API
API_V1_STR=/api/v1
```
## Database
The application uses SQLite as the database. The database file is stored at `/app/storage/db/db.sqlite`. Make sure the directory exists or is created at runtime.
## License
This project is licensed under the MIT License.