Automated Action 0474b30c3f Implement complete bookstore management API with FastAPI
- 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
2025-06-25 10:34:27 +00:00

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 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:

    pip install -r requirements.txt
    
  2. Set up environment variables:

    export STRIPE_SECRET_KEY=your_stripe_secret_key_here
    
  3. Run database migrations:

    alembic upgrade head
    
  4. 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:

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