From cedb471722439bd71d03e792e5d68acfa0a0243a Mon Sep 17 00:00:00 2001 From: wowlikon Date: Tue, 27 May 2025 13:09:50 +0300 Subject: [PATCH] README and some fixes --- .env.example | 3 +++ Dockerfile | 2 +- README.md | 17 +++++++++++++++++ app/models.py | 6 +++--- docker-compose.yml | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 .env.example create mode 100644 README.md diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..787729d --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +POSTGRES_USER=postgres +POSTGRES_PASSWORD=password +POSTGRES_DB=mydatabase diff --git a/Dockerfile b/Dockerfile index d1b9371..0e7f45b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9 +FROM python:3.11 WORKDIR /code diff --git a/README.md b/README.md new file mode 100644 index 0000000..65e623f --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Book API + +## Installation +1. Clone the repository: `git clone https://github.com/yourusername/bookapi.git` +2. Navigate to the project directory: `cd bookapi` +3. Copy and configure environment variables: `cp .env.example .env` +4. Build docker-compose: `docker-compose build` +5. Run the application: `docker-compose up` + +## Usage + +## TODO +* Usage instructions +* Split models for api and db +* Add documentation for API endpoints +* Add alembic migrations +* Add tests diff --git a/app/models.py b/app/models.py index 7405afe..b2c703e 100644 --- a/app/models.py +++ b/app/models.py @@ -1,4 +1,4 @@ -from typing import Optional, List +from typing import List from sqlmodel import SQLModel, Field, Relationship # Relationship model @@ -8,14 +8,14 @@ class AuthorBookLink(SQLModel, table=True): # Author model class Author(SQLModel, table=True): - id: Optional[int] = Field(primary_key=True, index=True) + id: int | None = Field(primary_key=True, index=True) name: str books: List["Book"] = Relationship(back_populates="authors", link_model=AuthorBookLink) # Book model class Book(SQLModel, table=True): - id: Optional[int] = Field(primary_key=True, index=True) + id: int | None = Field(primary_key=True, index=True) title: str description: str authors: List[Author] = Relationship(back_populates="books", link_model=AuthorBookLink) diff --git a/docker-compose.yml b/docker-compose.yml index 69ba43a..ebfd929 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: volumes: - postgres_data:/var/lib/postgresql/data - web: + api: build: . ports: - "8000:8000"