# Bookstore Management API A comprehensive REST API for managing a bookstore with inventory management and Stripe payment processing built with FastAPI. ## Features - **Book Management**: Complete CRUD operations for books with search and filtering - **Inventory Management**: Track stock levels, reserve items, and manage restocking - **Order Management**: Handle customer orders with status tracking - **Payment Processing**: Secure payment handling with Stripe integration - **Database**: SQLite database with SQLAlchemy ORM and Alembic migrations ## API Endpoints ### Books - `GET /api/v1/books/` - List all books with filtering options - `POST /api/v1/books/` - Create a new book - `GET /api/v1/books/{book_id}` - Get a specific book - `PUT /api/v1/books/{book_id}` - Update a book - `DELETE /api/v1/books/{book_id}` - Deactivate a book ### Inventory - `GET /api/v1/inventory/` - List inventory items - `POST /api/v1/inventory/` - Create inventory entry - `GET /api/v1/inventory/{inventory_id}` - Get inventory item - `GET /api/v1/inventory/book/{book_id}` - Get inventory by book - `PUT /api/v1/inventory/{inventory_id}` - Update inventory - `POST /api/v1/inventory/{inventory_id}/restock` - Restock items - `POST /api/v1/inventory/{inventory_id}/reserve` - Reserve items - `POST /api/v1/inventory/{inventory_id}/release` - Release reserved items ### Orders - `GET /api/v1/orders/` - List orders with filtering - `POST /api/v1/orders/` - Create a new order - `GET /api/v1/orders/{order_id}` - Get order details - `PUT /api/v1/orders/{order_id}/status` - Update order status - `POST /api/v1/orders/payment-intent` - Create Stripe payment intent - `POST /api/v1/orders/{order_id}/confirm-payment` - Confirm payment - `DELETE /api/v1/orders/{order_id}` - Cancel order ### System - `GET /` - API information - `GET /health` - Health check endpoint - `GET /docs` - Interactive API documentation - `GET /redoc` - ReDoc API documentation ## Installation & Setup 1. Install dependencies: ```bash pip install -r requirements.txt ``` 2. Set up environment variables: ```bash export STRIPE_SECRET_KEY=your_stripe_secret_key_here ``` 3. Run database migrations: ```bash alembic upgrade head ``` 4. Start the application: ```bash uvicorn main:app --reload --host 0.0.0.0 --port 8000 ``` ## Environment Variables The following environment variables need to be set: - `STRIPE_SECRET_KEY`: Your Stripe secret key for payment processing ## Database The application uses SQLite with the database file located at `/app/storage/db/db.sqlite`. The database schema includes: - **books**: Book catalog with details - **inventory**: Stock management for books - **orders**: Customer orders - **order_items**: Items within orders ## Development ### Linting Run code linting with: ```bash ruff check --fix . ``` ### Database Migrations Create new migrations: ```bash alembic revision --autogenerate -m "Description" ``` Apply migrations: ```bash alembic upgrade head ``` ## API Documentation Once the server is running, visit: - http://localhost:8000/docs for Swagger UI - http://localhost:8000/redoc for ReDoc - http://localhost:8000/openapi.json for OpenAPI schema ## Payment Flow 1. Create an order with items 2. Create a payment intent for the order 3. Process the payment on the frontend using Stripe 4. Confirm the payment to update order status 5. Manage order fulfillment through status updates ## Error Handling The API provides comprehensive error handling with appropriate HTTP status codes and descriptive error messages for various scenarios including: - Invalid data validation - Insufficient inventory - Payment processing errors - Resource not found