Skip to content

Commit aa652fe

Browse files
grigoriev-semyondyakovri
authored andcommitted
Add simplelogic, fix tests
Fix isort Fix black Attempt to fix frontend style check Attempt to fix frontend style check del region pnpm del
1 parent 2ed0c9c commit aa652fe

14 files changed

Lines changed: 86 additions & 48 deletions

File tree

.github/workflows/checks.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ jobs:
9999
steps:
100100
- name: Checkout
101101
uses: actions/checkout@v4
102-
- name: cd into folder
103-
run: cd frontend
104102
- uses: actions/setup-node@v3
105103
with:
106104
node-version: '18'

backend/migrations/env.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from logging.config import fileConfig
22

33
from alembic import context
4-
from sqlalchemy import engine_from_config, pool
5-
64
from my_app_api.models.base import Base
75
from my_app_api.settings import get_settings
8-
6+
from sqlalchemy import engine_from_config, pool
97

108
# this is the Alembic Config object, which provides
119
# access to the values within the .ini file in use.
@@ -61,7 +59,7 @@ def run_migrations_online():
6159
6260
"""
6361
configuration = config.get_section(config.config_ini_section)
64-
configuration['sqlalchemy.url'] = str(settings.DB_DSN)
62+
configuration["sqlalchemy.url"] = str(settings.DB_DSN)
6563
connectable = engine_from_config(
6664
configuration,
6765
prefix="sqlalchemy.",

backend/my_app_api/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import os
22

3-
43
__version__ = os.getenv("APP_VERSION", "dev")

backend/my_app_api/__main__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import uvicorn
2-
32
from my_app_api.routes import app
43

5-
6-
if __name__ == '__main__':
4+
if __name__ == "__main__":
75
uvicorn.run(app)

backend/my_app_api/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class APIError(Exception):
2+
"""Base class for API errors"""
3+
4+
def __init__(self, message: str) -> None:
5+
super().__init__(message)

backend/my_app_api/routes/__init__.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44
from fastapi.middleware.cors import CORSMiddleware
55
from fastapi.staticfiles import StaticFiles
66
from fastapi_sqlalchemy import DBSessionMiddleware
7-
87
from my_app_api import __version__
98
from my_app_api.settings import get_settings
109

11-
from .click import router as click_router
12-
10+
from .touch import router as touch_router
1311

1412
settings = get_settings()
1513
logger = logging.getLogger(__name__)
1614
app = FastAPI(
17-
title='Мое приложение',
18-
description='Бэкэнд приложения-примера',
15+
title="Мое приложение",
16+
description="Бэкэнд приложения-примера",
1917
version=__version__,
2018
# Отключаем нелокальную документацию
21-
root_path=settings.ROOT_PATH if __version__ != 'dev' else '',
22-
docs_url='/swagger',
19+
root_path=settings.ROOT_PATH if __version__ != "dev" else "",
20+
docs_url="/swagger",
2321
redoc_url=None,
2422
)
2523

@@ -39,10 +37,16 @@
3937

4038
if settings.UI_DIR_PATH:
4139
logger.debug("Enabling UI")
42-
app.mount("/ui", app=StaticFiles(directory=settings.UI_DIR_PATH, html=True), name="ui")
40+
app.mount(
41+
"/ui", app=StaticFiles(directory=settings.UI_DIR_PATH, html=True), name="ui"
42+
)
4343

4444
if settings.DOCS_DIR_PATH:
4545
logger.debug("Enabling Docs")
46-
app.mount("/docs", app=StaticFiles(directory=settings.DOCS_DIR_PATH, html=True), name="docs")
46+
app.mount(
47+
"/docs",
48+
app=StaticFiles(directory=settings.DOCS_DIR_PATH, html=True),
49+
name="docs",
50+
)
4751

48-
app.include_router(click_router)
52+
app.include_router(touch_router)

backend/my_app_api/routes/click.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

backend/my_app_api/routes/touch.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import logging
2+
3+
from auth_lib.fastapi import UnionAuth
4+
from fastapi import APIRouter, Depends
5+
from pydantic import BaseModel
6+
7+
logger = logging.getLogger(__name__)
8+
router = APIRouter(prefix="/example", tags=["Example"])
9+
10+
CLICKS: dict[int, int] = {}
11+
12+
13+
class WhoAmI(BaseModel):
14+
id: int
15+
16+
17+
class TouchGet(WhoAmI):
18+
count: int
19+
20+
21+
@router.get("/whoami", response_model=WhoAmI)
22+
def whoami(auth=Depends(UnionAuth(allow_none=False))):
23+
return {"id": auth["id"]}
24+
25+
26+
@router.post("/touch", response_model=TouchGet)
27+
def touch(auth=Depends(UnionAuth(allow_none=False))):
28+
if auth["id"] not in CLICKS:
29+
CLICKS[auth["id"]] = 0
30+
CLICKS[auth["id"]] += 1
31+
return {"id": auth["id"], "count": CLICKS[auth["id"]]}

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.black]
22
line-length = 120
3-
target-version = ['py312']
3+
target-version = ['py311']
44
skip-string-normalization = true
55

66
[tool.isort]

backend/requirements.dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ isort
55
pytest
66
pytest-cov
77
pytest-mock
8+
auth-lib-profcomff[testing]

0 commit comments

Comments
 (0)