refactoring
parent
15549f53d5
commit
b22f6a3beb
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from .ref_repo import RefRepository
|
||||
from .user import UserRepository
|
||||
from .user_repo import UserRepository
|
||||
|
||||
__all__ = (
|
||||
"UserRepository",
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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:
|
|
@ -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",
|
||||
)
|
|
@ -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
|
|
@ -1,5 +1,5 @@
|
|||
from .auth_service import AuthService, get_current_user
|
||||
from .user import UserService
|
||||
from .user_service import UserService
|
||||
|
||||
__all__ = (
|
||||
"UserService",
|
||||
|
|
|
@ -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})
|
||||
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,3 @@
|
|||
from .sqlalchemy_uow import UnitOfWork
|
||||
|
||||
__all__ = ("UnitOfWork",)
|
Loading…
Reference in New Issue