Automated Action a9210ca8ed Create manga inventory API with FastAPI and SQLite
- Implemented CRUD operations for manga, authors, publishers, and genres
- Added search and filtering functionality
- Set up SQLAlchemy ORM with SQLite database
- Configured Alembic for database migrations
- Implemented logging with Loguru
- Added comprehensive API documentation
- Set up error handling and validation
- Added ruff for linting and formatting
2025-05-30 12:29:35 +00:00

171 lines
4.1 KiB
Markdown

# Manga Inventory API
A FastAPI-based RESTful API for managing a manga book inventory.
## Features
- Complete CRUD operations for manga books, authors, publishers, and genres
- Search and filtering capabilities for manga inventory
- SQLite database with SQLAlchemy ORM
- Alembic for database migrations
- Pydantic for data validation
- Comprehensive logging with Loguru
## Tech Stack
- Python 3.10+
- FastAPI
- SQLAlchemy
- Alembic
- Pydantic
- SQLite
- Loguru
## Project Structure
```
manga-inventory-api/
├── alembic.ini
├── app/
│ ├── api/
│ │ ├── deps.py
│ │ └── v1/
│ │ ├── api.py
│ │ └── endpoints/
│ │ ├── author.py
│ │ ├── genre.py
│ │ ├── manga.py
│ │ └── publisher.py
│ ├── core/
│ │ ├── config.py
│ │ └── logging.py
│ ├── crud/
│ │ ├── author.py
│ │ ├── base.py
│ │ ├── genre.py
│ │ ├── manga.py
│ │ └── publisher.py
│ ├── db/
│ │ ├── base.py
│ │ ├── base_class.py
│ │ └── session.py
│ ├── models/
│ │ └── manga.py
│ └── schemas/
│ ├── author.py
│ ├── genre.py
│ ├── manga.py
│ └── publisher.py
├── main.py
├── migrations/
│ ├── env.py
│ ├── README
│ ├── script.py.mako
│ └── versions/
│ └── 01_initial_tables.py
├── pyproject.toml
└── requirements.txt
```
## Setup and Installation
1. Clone the repository:
```bash
git clone <repository-url>
cd manga-inventory-api
```
2. Create a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install the dependencies:
```bash
pip install -r requirements.txt
```
4. Run the database migrations:
```bash
alembic upgrade head
```
5. Start the development server:
```bash
uvicorn main:app --reload
```
6. The API will be available at http://localhost:8000
## API Endpoints
### Health Check
- `GET /health` - Check if the API is running
### Manga
- `GET /api/v1/manga` - List all manga
- `POST /api/v1/manga` - Create a new manga
- `GET /api/v1/manga/{manga_id}` - Get a specific manga
- `PUT /api/v1/manga/{manga_id}` - Update a manga
- `DELETE /api/v1/manga/{manga_id}` - Delete a manga
### Authors
- `GET /api/v1/authors` - List all authors
- `POST /api/v1/authors` - Create a new author
- `GET /api/v1/authors/{author_id}` - Get a specific author
- `PUT /api/v1/authors/{author_id}` - Update an author
- `DELETE /api/v1/authors/{author_id}` - Delete an author
### Publishers
- `GET /api/v1/publishers` - List all publishers
- `POST /api/v1/publishers` - Create a new publisher
- `GET /api/v1/publishers/{publisher_id}` - Get a specific publisher
- `PUT /api/v1/publishers/{publisher_id}` - Update a publisher
- `DELETE /api/v1/publishers/{publisher_id}` - Delete a publisher
### Genres
- `GET /api/v1/genres` - List all genres
- `POST /api/v1/genres` - Create a new genre
- `GET /api/v1/genres/{genre_id}` - Get a specific genre
- `PUT /api/v1/genres/{genre_id}` - Update a genre
- `DELETE /api/v1/genres/{genre_id}` - Delete a genre
## Filtering and Searching
You can filter manga using query parameters:
```
GET /api/v1/manga?title=Naruto&in_stock=true
```
Available filters:
- `title` - Filter by title (partial match)
- `author_id` - Filter by author ID
- `publisher_id` - Filter by publisher ID
- `genre_id` - Filter by genre ID
- `in_stock` - Filter by stock availability (true/false)
## Documentation
Interactive API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## Development
### Code Formatting and Linting
The project uses Ruff for linting and formatting:
```bash
# Format code
ruff format .
# Lint code
ruff check .
# Fix auto-fixable linting issues
ruff check --fix .
```