From fd9e87813412219d7417857e0757dca8a1ba138e Mon Sep 17 00:00:00 2001 From: wowlikon Date: Tue, 24 Jun 2025 13:59:54 +0300 Subject: [PATCH] Some documentation fixes for migrations and endpoints. --- README.md | 71 +++++++++++++++++++++------------------------- docker-compose.yml | 4 +-- migrations/env.py | 1 + 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 45a1bcd..41ca817 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LibraryAPI -## WARNING: The documentation is now out of date. +## WARNING: Documentation may be partially out of date at this time. This project is a test web application built using FastAPI, a modern web framework for creating APIs in Python. It showcases the use of Pydantic for data validation, SQLModel for database interactions, Alembic for migration management, PostgreSQL as the database system, and Docker Compose for easy deployment. @@ -25,64 +25,61 @@ For development: 2. Navigate to the project directory: ```bash - cd bookapi + cd libraryapi ``` -3. Copy and configure environment variables: +3. Configure environment variables: ```bash - cp .env.example .env + edit .env ``` 4. Build the Docker containers: ```bash - docker-compose build --no-cache + docker compose build ``` 5. Run the application: ```bash - docker-compose up + docker compose up api ``` For make new migrations: ```bash - docker-compose run api alembic revision --autogenerate -m "Migration name" + docker compose run --rm -T api alembic revision --autogenerate -m "Migration name" ``` -For apply migrations: - - 1. Build the Docker containers: - ```bash - docker-compose build --no-cache - ``` - - 2. Run database container: - ```bash - docker-compose up -d db - ``` - - 3. Run this command: +For run tests: ```bash - docker-compose run --rm api alembic upgrade head + docker compose up test ``` - ### **API Endpoints** **Authors** -| Method | Endpoint | Description | -|--------|-------------------|--------------------------------------| -| POST | `/author` | Create a new author | -| GET | `/author` | Retrieve a list of all authors | -| PUT | `/author/{id}` | Update a specific author by ID | -| DELETE | `/author/{id}` | Delete a specific author by ID | +| Method | Endpoint | Description | +|--------|-----------------------|------------------------------------------------| +| POST | `/authors` | Create a new author | +| GET | `/authors` | Retrieve a list of all authors | +| GET | `/authors/{id}` | Retrieve a specific author by ID | +| PUT | `/authors/{id}` | Update a specific author by ID | +| DELETE | `/authors/{id}` | Delete a specific author by ID | +| GET | `/authors/{id}/books` | Retrieve a list of books for a specific author | **Books** -| Method | Endpoint | Description | -|--------|-------------------|--------------------------------------| -| POST | `/books` | Create a new book | -| GET | `/books` | Retrieve a list of all books | -| PUT | `/books/{id}` | Update a specific book by ID | -| DELETE | `/books/{id}` | Delete a specific book by ID | +| Method | Endpoint | Description | +|--------|-----------------------|------------------------------------------------| +| POST | `/books` | Create a new book | +| GET | `/books` | Retrieve a list of all books | +| GET | `/book/{id}` | Retrieve a specific book by ID | +| PUT | `/books/{id}` | Update a specific book by ID | +| DELETE | `/books/{id}` | Delete a specific book by ID | +| GET | `/books/{id}/authors` | Retrieve a list of authors for a specific book | + +**Relationships** +| Method | Endpoint | Description | +|--------|-----------------------|------------------------------------------------| +| POST | `/relationships` | Add author-book relationship | +| DELETE | `/relationships` | Remove author-book relationship | ### **Technologies Used** @@ -98,8 +95,6 @@ For apply migrations: ### **TODO List** -- Split models files for API and database -- new structure (src/app, src/migrations?) -- Geners table -- Poetry - Implement tests +- Geners table +- Check and update documentation diff --git a/docker-compose.yml b/docker-compose.yml index bcbcf2b..1b564ac 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: db: - container_name: db_library + container_name: db image: postgres expose: - 5432 @@ -10,7 +10,7 @@ services: - ./.env api: - container_name: api_library + container_name: api build: . command: bash -c "alembic upgrade head && uvicorn library_service.main:app --reload --host 0.0.0.0 --port 8000" volumes: diff --git a/migrations/env.py b/migrations/env.py index 8ba4301..03052b9 100755 --- a/migrations/env.py +++ b/migrations/env.py @@ -6,6 +6,7 @@ from sqlalchemy import pool from sqlmodel import SQLModel from library_service.settings import POSTGRES_DATABASE_URL +print(POSTGRES_DATABASE_URL) # this is the Alembic Config object, which provides # access to the values within the .ini file in use.