
- Added comprehensive book management with CRUD operations - Implemented inventory tracking with stock management and reservations - Created order management system with status tracking - Integrated Stripe payment processing with payment intents - Added SQLite database with SQLAlchemy ORM and Alembic migrations - Implemented health check and API documentation endpoints - Added comprehensive error handling and validation - Configured CORS middleware for frontend integration
3.6 KiB
3.6 KiB
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 optionsPOST /api/v1/books/
- Create a new bookGET /api/v1/books/{book_id}
- Get a specific bookPUT /api/v1/books/{book_id}
- Update a bookDELETE /api/v1/books/{book_id}
- Deactivate a book
Inventory
GET /api/v1/inventory/
- List inventory itemsPOST /api/v1/inventory/
- Create inventory entryGET /api/v1/inventory/{inventory_id}
- Get inventory itemGET /api/v1/inventory/book/{book_id}
- Get inventory by bookPUT /api/v1/inventory/{inventory_id}
- Update inventoryPOST /api/v1/inventory/{inventory_id}/restock
- Restock itemsPOST /api/v1/inventory/{inventory_id}/reserve
- Reserve itemsPOST /api/v1/inventory/{inventory_id}/release
- Release reserved items
Orders
GET /api/v1/orders/
- List orders with filteringPOST /api/v1/orders/
- Create a new orderGET /api/v1/orders/{order_id}
- Get order detailsPUT /api/v1/orders/{order_id}/status
- Update order statusPOST /api/v1/orders/payment-intent
- Create Stripe payment intentPOST /api/v1/orders/{order_id}/confirm-payment
- Confirm paymentDELETE /api/v1/orders/{order_id}
- Cancel order
System
GET /
- API informationGET /health
- Health check endpointGET /docs
- Interactive API documentationGET /redoc
- ReDoc API documentation
Installation & Setup
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
export STRIPE_SECRET_KEY=your_stripe_secret_key_here
-
Run database migrations:
alembic upgrade head
-
Start the application:
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:
ruff check --fix .
Database Migrations
Create new migrations:
alembic revision --autogenerate -m "Description"
Apply migrations:
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
- Create an order with items
- Create a payment intent for the order
- Process the payment on the frontend using Stripe
- Confirm the payment to update order status
- 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