mirror of
https://github.com/wowlikon/LibraryAPI.git
synced 2025-12-11 21:30:46 +00:00
Some documentation fixes for migrations and endpoints.
This commit is contained in:
59
README.md
59
README.md
@@ -1,6 +1,6 @@
|
|||||||
# LibraryAPI
|
# 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.
|
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:
|
2. Navigate to the project directory:
|
||||||
```bash
|
```bash
|
||||||
cd bookapi
|
cd libraryapi
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Copy and configure environment variables:
|
3. Configure environment variables:
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
edit .env
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Build the Docker containers:
|
4. Build the Docker containers:
|
||||||
```bash
|
```bash
|
||||||
docker-compose build --no-cache
|
docker compose build
|
||||||
```
|
```
|
||||||
|
|
||||||
5. Run the application:
|
5. Run the application:
|
||||||
```bash
|
```bash
|
||||||
docker-compose up
|
docker compose up api
|
||||||
```
|
```
|
||||||
|
|
||||||
For make new migrations:
|
For make new migrations:
|
||||||
```bash
|
```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:
|
For run tests:
|
||||||
|
|
||||||
1. Build the Docker containers:
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose build --no-cache
|
docker compose up test
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run database container:
|
|
||||||
```bash
|
|
||||||
docker-compose up -d db
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Run this command:
|
|
||||||
```bash
|
|
||||||
docker-compose run --rm api alembic upgrade head
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### **API Endpoints**
|
### **API Endpoints**
|
||||||
|
|
||||||
**Authors**
|
**Authors**
|
||||||
| Method | Endpoint | Description |
|
| Method | Endpoint | Description |
|
||||||
|--------|-------------------|--------------------------------------|
|
|--------|-----------------------|------------------------------------------------|
|
||||||
| POST | `/author` | Create a new author |
|
| POST | `/authors` | Create a new author |
|
||||||
| GET | `/author` | Retrieve a list of all authors |
|
| GET | `/authors` | Retrieve a list of all authors |
|
||||||
| PUT | `/author/{id}` | Update a specific author by ID |
|
| GET | `/authors/{id}` | Retrieve a specific author by ID |
|
||||||
| DELETE | `/author/{id}` | Delete 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**
|
**Books**
|
||||||
| Method | Endpoint | Description |
|
| Method | Endpoint | Description |
|
||||||
|--------|-------------------|--------------------------------------|
|
|--------|-----------------------|------------------------------------------------|
|
||||||
| POST | `/books` | Create a new book |
|
| POST | `/books` | Create a new book |
|
||||||
| GET | `/books` | Retrieve a list of all books |
|
| 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 |
|
| PUT | `/books/{id}` | Update a specific book by ID |
|
||||||
| DELETE | `/books/{id}` | Delete 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**
|
### **Technologies Used**
|
||||||
@@ -98,8 +95,6 @@ For apply migrations:
|
|||||||
|
|
||||||
### **TODO List**
|
### **TODO List**
|
||||||
|
|
||||||
- Split models files for API and database
|
|
||||||
- new structure (src/app, src/migrations?)
|
|
||||||
- Geners table
|
|
||||||
- Poetry
|
|
||||||
- Implement tests
|
- Implement tests
|
||||||
|
- Geners table
|
||||||
|
- Check and update documentation
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
container_name: db_library
|
container_name: db
|
||||||
image: postgres
|
image: postgres
|
||||||
expose:
|
expose:
|
||||||
- 5432
|
- 5432
|
||||||
@@ -10,7 +10,7 @@ services:
|
|||||||
- ./.env
|
- ./.env
|
||||||
|
|
||||||
api:
|
api:
|
||||||
container_name: api_library
|
container_name: api
|
||||||
build: .
|
build: .
|
||||||
command: bash -c "alembic upgrade head && uvicorn library_service.main:app --reload --host 0.0.0.0 --port 8000"
|
command: bash -c "alembic upgrade head && uvicorn library_service.main:app --reload --host 0.0.0.0 --port 8000"
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from sqlalchemy import pool
|
|||||||
from sqlmodel import SQLModel
|
from sqlmodel import SQLModel
|
||||||
|
|
||||||
from library_service.settings import POSTGRES_DATABASE_URL
|
from library_service.settings import POSTGRES_DATABASE_URL
|
||||||
|
print(POSTGRES_DATABASE_URL)
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
# this is the Alembic Config object, which provides
|
||||||
# access to the values within the .ini file in use.
|
# access to the values within the .ini file in use.
|
||||||
|
|||||||
Reference in New Issue
Block a user