diff --git a/.env b/.env index 5419367..9c04ee3 100644 --- a/.env +++ b/.env @@ -6,6 +6,7 @@ SQL_TEST_DB=testdb SQL_HOST=db SQL_USER=user SQL_PASS=secret +SQL_URL=postgresql+asyncpg://${SQL_USER}:${SQL_PASS}@${SQL_HOST}/${SQL_DB} ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 diff --git a/app/api/nonsense.py b/app/api/nonsense.py index 7cf7ac6..ebcad4d 100644 --- a/app/api/nonsense.py +++ b/app/api/nonsense.py @@ -36,7 +36,7 @@ async def update_nonsense( db_session: AsyncSession = Depends(get_db), ): nonsense = await Nonsense.find(db_session, name) - await nonsense.update(db_session, **payload.dict()) + await nonsense.update(db_session, **payload.model_dump()) return nonsense @@ -45,6 +45,6 @@ async def merge_nonsense( payload: NonsenseSchema, db_session: AsyncSession = Depends(get_db), ): - nonsense = Nonsense(**payload.dict()) + nonsense = Nonsense(**payload.model_dump()) await nonsense.save_or_update(db_session) return nonsense diff --git a/app/api/shakespeare.py b/app/api/shakespeare.py index 170d33e..1463e52 100644 --- a/app/api/shakespeare.py +++ b/app/api/shakespeare.py @@ -1,7 +1,6 @@ from typing import Annotated from fastapi import APIRouter, Depends, Query -from pydantic import Required from sqlalchemy.ext.asyncio import AsyncSession from app.database import get_db @@ -14,7 +13,7 @@ router = APIRouter(prefix="/v1/shakespeare") "/", ) async def find_paragraph( - character: Annotated[str, Query(description="Character name")] = Required, + character: Annotated[str, Query(description="Character name")], db_session: AsyncSession = Depends(get_db), ): return await Paragraph.find(db_session=db_session, character=character) diff --git a/app/api/stuff.py b/app/api/stuff.py index 6f60f6e..11bd8fb 100644 --- a/app/api/stuff.py +++ b/app/api/stuff.py @@ -54,5 +54,5 @@ async def update_stuff( db_session: AsyncSession = Depends(get_db), ): stuff = await Stuff.find(db_session, name) - await stuff.update(db_session, **payload.dict()) + await stuff.update(db_session, **payload.model_dump()) return stuff diff --git a/app/config.py b/app/config.py index ded6e05..0905c18 100644 --- a/app/config.py +++ b/app/config.py @@ -1,18 +1,12 @@ import os from functools import lru_cache -from pydantic import BaseSettings, PostgresDsn +from pydantic import PostgresDsn +from pydantic_settings import BaseSettings class Settings(BaseSettings): - asyncpg_url: PostgresDsn = PostgresDsn.build( - scheme="postgresql+asyncpg", - user=os.getenv("SQL_USER"), - password=os.getenv("POSTGRES_PASSWORD"), - host=os.getenv("SQL_HOST"), - port="5432", - path=f"/{os.getenv('SQL_DB') or ''}", - ) + asyncpg_url: PostgresDsn = os.getenv("SQL_URL") @lru_cache diff --git a/app/database.py b/app/database.py index 8ebd60f..20a4351 100644 --- a/app/database.py +++ b/app/database.py @@ -10,7 +10,7 @@ global_settings = config.get_settings() logger = AppLogger.__call__().get_logger() engine = create_async_engine( - global_settings.asyncpg_url, + global_settings.asyncpg_url.unicode_string(), future=True, echo=True, ) diff --git a/app/schemas/nnonsense.py b/app/schemas/nnonsense.py index 8c691c9..627d72c 100644 --- a/app/schemas/nnonsense.py +++ b/app/schemas/nnonsense.py @@ -14,8 +14,8 @@ class NonsenseSchema(BaseModel): ) class Config: - orm_mode = True - schema_extra = { + from_attributes = True + json_schema_extra = { "example": { "name": "Name for Some Nonsense", "description": "Some Nonsense Description", @@ -38,8 +38,8 @@ class NonsenseResponse(BaseModel): ) class Config: - orm_mode = True - schema_extra = { + from_attributes = True + json_schema_extra = { "example": { "config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "name": "Name for Some Nonsense", diff --git a/app/schemas/stuff.py b/app/schemas/stuff.py index c7a3f21..642d4eb 100644 --- a/app/schemas/stuff.py +++ b/app/schemas/stuff.py @@ -14,8 +14,8 @@ class StuffSchema(BaseModel): ) class Config: - orm_mode = True - schema_extra = { + from_attributes = True + json_schema_extra = { "example": { "name": "Name for Some Stuff", "description": "Some Stuff Description", @@ -38,8 +38,8 @@ class StuffResponse(BaseModel): ) class Config: - orm_mode = True - schema_extra = { + from_attributes = True + json_schema_extra = { "example": { "config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "name": "Name for Some Stuff",