mirror of
https://github.com/wowlikon/LiB.git
synced 2026-02-04 04:31:09 +00:00
Добавление авторизации и фронтэнда
This commit is contained in:
+18
-11
@@ -1,59 +1,66 @@
|
||||
"""Модуль настроек проекта"""
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from fastapi import FastAPI
|
||||
from sqlmodel import create_engine, SQLModel, Session
|
||||
from sqlmodel import Session, create_engine
|
||||
from toml import load
|
||||
|
||||
load_dotenv()
|
||||
|
||||
with open("pyproject.toml") as f:
|
||||
with open("pyproject.toml", 'r', encoding='utf-8') as f:
|
||||
config = load(f)
|
||||
|
||||
|
||||
# Dependency to get the FastAPI application instance
|
||||
def get_app() -> FastAPI:
|
||||
"""Dependency, для получение экземплярра FastAPI application"""
|
||||
return FastAPI(
|
||||
title=config["tool"]["poetry"]["name"],
|
||||
description=config["tool"]["poetry"]["description"],
|
||||
version=config["tool"]["poetry"]["version"],
|
||||
openapi_tags=[
|
||||
{
|
||||
"name": "authentication",
|
||||
"description": "Авторизация пользователя."
|
||||
},
|
||||
{
|
||||
"name": "authors",
|
||||
"description": "Operations with authors.",
|
||||
"description": "Действия с авторами.",
|
||||
},
|
||||
{
|
||||
"name": "books",
|
||||
"description": "Operations with books.",
|
||||
"description": "Действия с книгами.",
|
||||
},
|
||||
{
|
||||
"name": "genres",
|
||||
"description": "Operations with genres.",
|
||||
"description": "Действия с жанрами.",
|
||||
},
|
||||
{
|
||||
"name": "relations",
|
||||
"description": "Operations with relations.",
|
||||
"description": "Действия с связями.",
|
||||
},
|
||||
{
|
||||
"name": "misc",
|
||||
"description": "Miscellaneous operations.",
|
||||
"description": "Прочие.",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
HOST = os.getenv("POSTGRES_HOST")
|
||||
PORT = os.getenv("POSTGRES_PORT")
|
||||
USER = os.getenv("POSTGRES_USER")
|
||||
PASSWORD = os.getenv("POSTGRES_PASSWORD")
|
||||
DATABASE = os.getenv("POSTGRES_DB")
|
||||
HOST = os.getenv("POSTGRES_SERVER")
|
||||
|
||||
if not USER or not PASSWORD or not DATABASE or not HOST:
|
||||
raise ValueError("Missing environment variables")
|
||||
|
||||
POSTGRES_DATABASE_URL = f"postgresql://{USER}:{PASSWORD}@{HOST}:5432/{DATABASE}"
|
||||
POSTGRES_DATABASE_URL = f"postgresql://{USER}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}"
|
||||
engine = create_engine(POSTGRES_DATABASE_URL, echo=True, future=True)
|
||||
|
||||
|
||||
# Dependency to get a database session
|
||||
def get_session():
|
||||
"""Dependency, для получение сессии БД"""
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
||||
Reference in New Issue
Block a user