diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f781327..d8a08e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: rev: v3.3.1 hooks: - id: pyupgrade - args: [ --py310-plus ] + args: [ --py311-plus ] # Форматирует код под PEP8 - repo: https://github.com/pre-commit/mirrors-autopep8 @@ -33,20 +33,20 @@ repos: args: [ "-i", "--in-place", "--max-line-length=120" ] # Сканер стилистических ошибок, нарушающие договоренности PEP8 - - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - exclude: __init__.py - args: [ "--ignore=E501,F821", "--max-line-length=120" ] + # - repo: https://github.com/PyCQA/flake8 + # rev: 6.0.0 + # hooks: + # - id: flake8 + # exclude: __init__.py + # args: [ "--ignore=E501,F821", "--max-line-length=120" ] # Форматирует код под PEP8 c помощью black - - repo: https://github.com/psf/black - rev: 23.1.0 - hooks: - - id: black - language_version: python3.10 - args: [ "--line-length=120" ] + # - repo: https://github.com/psf/black + # rev: 23.1.0 + # hooks: + # - id: black + # language_version: python3.10 + # args: [ "--line-length=120" ] # Проверка статических типов с помощью mypy - repo: https://github.com/pre-commit/mirrors-mypy diff --git a/test_api/app.py b/test_api/app.py index e03c132..13d71f7 100644 --- a/test_api/app.py +++ b/test_api/app.py @@ -2,8 +2,7 @@ from contextlib import asynccontextmanager from fastapi import FastAPI -from .routers.auth import router as auth_router -from .routers.user import router as user_router +from .routers import auth_router, user_router @asynccontextmanager diff --git a/test_api/di.py b/test_api/di.py index 8baa296..bff7fbf 100644 --- a/test_api/di.py +++ b/test_api/di.py @@ -2,7 +2,7 @@ from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_asyn from .config import get_settings from .services import AuthService, UserService -from .uow.uow_base import UnitOfWork +from .uow import UnitOfWork async_engine = create_async_engine( url=get_settings().db.get_db_url, diff --git a/test_api/repositories/__init__.py b/test_api/repositories/__init__.py index c0293b1..f1666c2 100644 --- a/test_api/repositories/__init__.py +++ b/test_api/repositories/__init__.py @@ -1,5 +1,5 @@ from .ref_repo import RefRepository -from .user import UserRepository +from .user_repo import UserRepository __all__ = ( "UserRepository", diff --git a/test_api/repositories/ref_repo.py b/test_api/repositories/ref_repo.py index da70d93..88ec29f 100644 --- a/test_api/repositories/ref_repo.py +++ b/test_api/repositories/ref_repo.py @@ -1,18 +1,16 @@ -from uuid import UUID - from sqlalchemy import insert from sqlalchemy.ext.asyncio.session import AsyncSession from ..models import RefModel -from ..schemas import RefReadDTO +from ..schemas import RefReadDTO, UserAuthDTO class RefRepository: def __init__(self, session: AsyncSession): self.session = session - async def add_ref(self, referer: UUID) -> RefReadDTO: - stmt = insert(RefModel).values(referer=referer, is_active=True).returning(RefModel) + async def add_ref(self, user: UserAuthDTO) -> RefReadDTO: + stmt = insert(RefModel).values(referer=user.id, is_active=True, referals=[]).returning(RefModel) res = await self.session.execute(stmt) return RefReadDTO.model_validate(res.scalar_one()) diff --git a/test_api/repositories/user.py b/test_api/repositories/user_repo.py similarity index 93% rename from test_api/repositories/user.py rename to test_api/repositories/user_repo.py index af7f259..af3d680 100644 --- a/test_api/repositories/user.py +++ b/test_api/repositories/user_repo.py @@ -2,7 +2,7 @@ from sqlalchemy import insert, select from sqlalchemy.ext.asyncio.session import AsyncSession from ..models import UserModel -from ..schemas.user_schema import UserDBDTO, UserReadDTO +from ..schemas import UserDBDTO, UserReadDTO class UserRepository: diff --git a/test_api/routers/__init__.py b/test_api/routers/__init__.py index e69de29..27367ac 100644 --- a/test_api/routers/__init__.py +++ b/test_api/routers/__init__.py @@ -0,0 +1,7 @@ +from .auth_route import router as auth_router +from .user_route import router as user_router + +__all__ = ( + "auth_router", + "user_router", +) diff --git a/test_api/routers/auth.py b/test_api/routers/auth_route.py similarity index 100% rename from test_api/routers/auth.py rename to test_api/routers/auth_route.py diff --git a/test_api/routers/user.py b/test_api/routers/user_route.py similarity index 90% rename from test_api/routers/user.py rename to test_api/routers/user_route.py index c3aecde..101ce89 100644 --- a/test_api/routers/user.py +++ b/test_api/routers/user_route.py @@ -22,7 +22,6 @@ async def create_refer_code( user_service: UserService = Depends(get_user_service), user: UserAuthDTO = Depends(get_current_user), ): - print(user) - res = await user_service.create_ref(email=user.email) + res = await user_service.create_ref(user=user) return res diff --git a/test_api/services/__init__.py b/test_api/services/__init__.py index a879705..8eb35d3 100644 --- a/test_api/services/__init__.py +++ b/test_api/services/__init__.py @@ -1,5 +1,5 @@ from .auth_service import AuthService, get_current_user -from .user import UserService +from .user_service import UserService __all__ = ( "UserService", diff --git a/test_api/services/auth_service.py b/test_api/services/auth_service.py index a2b23d7..3471e33 100644 --- a/test_api/services/auth_service.py +++ b/test_api/services/auth_service.py @@ -6,9 +6,8 @@ from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm from jose import JWTError, jwt from passlib.context import CryptContext -from test_api.uow.uow_base import UnitOfWork - from ..schemas import TokenSchema, UserAuthDTO +from ..uow import UnitOfWork pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") @@ -49,9 +48,7 @@ class AuthService: self.uow = uow self.crypto_context = CryptContext(schemes="bcrypt") - async def authenticate( - self, login: OAuth2PasswordRequestForm = Depends() - ) -> TokenSchema | None: + async def authenticate(self, login: OAuth2PasswordRequestForm = Depends()) -> TokenSchema | None: async with self.uow: user = await self.uow.users.find_one(filter={"email": login.username}) diff --git a/test_api/services/user.py b/test_api/services/user_service.py similarity index 72% rename from test_api/services/user.py rename to test_api/services/user_service.py index 609a38c..4e2945e 100644 --- a/test_api/services/user.py +++ b/test_api/services/user_service.py @@ -1,7 +1,7 @@ from passlib.context import CryptContext -from ..schemas.user_schema import UserDBDTO, UserWriteDTO -from ..uow.uow_base import UnitOfWork +from ..schemas import UserAuthDTO, UserDBDTO, UserWriteDTO +from ..uow import UnitOfWork class UserService: @@ -22,8 +22,7 @@ class UserService: user = await self.uow.users.find_one(filter={"email": email}) return user - async def create_ref(self, email: str): + async def create_ref(self, user: UserAuthDTO): async with self.uow: - user = await self.uow.users.find_one(filter={"email": email}) - res = await self.uow.ref.add_ref(referer=user.id) + res = await self.uow.ref.add_ref(user=user) return res diff --git a/test_api/uow/__init__.py b/test_api/uow/__init__.py index e69de29..1133972 100644 --- a/test_api/uow/__init__.py +++ b/test_api/uow/__init__.py @@ -0,0 +1,3 @@ +from .sqlalchemy_uow import UnitOfWork + +__all__ = ("UnitOfWork",) diff --git a/test_api/uow/uow_base.py b/test_api/uow/sqlalchemy_uow.py similarity index 100% rename from test_api/uow/uow_base.py rename to test_api/uow/sqlalchemy_uow.py