This commit is contained in:
2026-07-16 16:31:36 +03:00
commit 3c8d2dd572
26 changed files with 1684 additions and 0 deletions

1
src/database/__init__.py Normal file
View File

@@ -0,0 +1 @@
'''environment for the work with db'''

1
src/docker/__init__.py Normal file
View File

@@ -0,0 +1 @@
'''docker files for the project'''

View File

0
src/docker/dockerfile Normal file
View File

1
src/errors/__init__.py Normal file
View File

@@ -0,0 +1 @@
'''error handling classes'''

View File

@@ -0,0 +1,14 @@
from fastapi import HTTPException
class Errors:
def __init__(self) -> None:
pass
def credentials_error(self, detail:str)->HTTPException:
raise HTTPException(status_code=401, detail=detail, headers={"WWW-Authenticate":"Bearer"})
def forbidden_error(self,detail:str)->HTTPException:
raise HTTPException(status_code=403, detail=detail, headers={"Cache-Control": "no-store, max-age=0"})
def not_found_error(self, detail:str)->HTTPException:
raise HTTPException(status_code=404, detail=detail, headers={"Cache-Control": "no-store, max-age=0"})

1
src/fake/__init__.py Normal file
View File

@@ -0,0 +1 @@
'''fake data for tests'''

1
src/migrations/README Normal file
View File

@@ -0,0 +1 @@
Generic single-database configuration.

View File

@@ -0,0 +1 @@
'''migrations of the database'''

78
src/migrations/env.py Normal file
View File

@@ -0,0 +1,78 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = None
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View File

@@ -0,0 +1,28 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
"""Upgrade schema."""
${upgrades if upgrades else "pass"}
def downgrade() -> None:
"""Downgrade schema."""
${downgrades if downgrades else "pass"}

1
src/models/__init__.py Normal file
View File

@@ -0,0 +1 @@
'''models for the project'''

View File

@@ -0,0 +1,14 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
class Base(BaseSettings):
pass
class Env(Base):
SECRET_KEY:str
ALGORITHM:str
ACCESS_TOKEN_EXPIRE_MINUTES:int
REFRESH_TOKEN_EXPIRE_DAYS:int
model_config=SettingsConfigDict(env_file="configs/.env", extra=None)
env_settings=Env()

1
src/reports/__init__.py Normal file
View File

@@ -0,0 +1 @@
'''Статистика по загруженным отчетам/ошибкам/тд через grafana/prometheus'''

1
src/tests/__init__.py Normal file
View File

@@ -0,0 +1 @@
'''unit, integr, e2e tests'''

1
src/web/__init__.py Normal file
View File

@@ -0,0 +1 @@
'''web server routes'''

View File

@@ -0,0 +1,9 @@
from fastapi import APIRouter
from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer
router=APIRouter(prefix="/protected")
oauth2_scheme=OAuth2PasswordBearer(tokenUrl="/protected/token")
@router.get("")
def protected()->dict:
return {"protected router": "Hello, this is a protected router"}