README and some fixes

This commit is contained in:
2025-05-27 13:09:50 +03:00
parent 6055467e97
commit cedb471722
5 changed files with 25 additions and 5 deletions

3
.env.example Normal file
View File

@@ -0,0 +1,3 @@
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_DB=mydatabase

View File

@@ -1,4 +1,4 @@
FROM python:3.9 FROM python:3.11
WORKDIR /code WORKDIR /code

17
README.md Normal file
View File

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

View File

@@ -1,4 +1,4 @@
from typing import Optional, List from typing import List
from sqlmodel import SQLModel, Field, Relationship from sqlmodel import SQLModel, Field, Relationship
# Relationship model # Relationship model
@@ -8,14 +8,14 @@ class AuthorBookLink(SQLModel, table=True):
# Author model # Author model
class Author(SQLModel, table=True): 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 name: str
books: List["Book"] = Relationship(back_populates="authors", link_model=AuthorBookLink) books: List["Book"] = Relationship(back_populates="authors", link_model=AuthorBookLink)
# Book model # Book model
class Book(SQLModel, table=True): 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 title: str
description: str description: str
authors: List[Author] = Relationship(back_populates="books", link_model=AuthorBookLink) authors: List[Author] = Relationship(back_populates="books", link_model=AuthorBookLink)

View File

@@ -10,7 +10,7 @@ services:
volumes: volumes:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
web: api:
build: . build: .
ports: ports:
- "8000:8000" - "8000:8000"