makeup project
This commit is contained in:
parent
a71176b09a
commit
b2ed5260a6
@ -1,23 +1,21 @@
|
|||||||
from datetime import datetime, timedelta, timezone
|
from src.utils.repository import SQLAlchemyRepository
|
||||||
from typing import Optional
|
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
from sqlalchemy import asc, desc, func, select
|
from .models import (
|
||||||
from sqlalchemy.sql.expression import nulls_last
|
User,
|
||||||
from sqlalchemy.sql.selectable import Select
|
Blog,
|
||||||
|
Post,
|
||||||
from src.settings import settings
|
Log
|
||||||
from src.utils.exceptions import (
|
|
||||||
RefreshClientInfoIncorrect,
|
|
||||||
RefreshException,
|
|
||||||
RefreshExpired,
|
|
||||||
)
|
|
||||||
from src.utils.repository import (
|
|
||||||
SQLAlchemyRepository,
|
|
||||||
_sentinel,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# from .models import (
|
class userRepository(SQLAlchemyRepository):
|
||||||
# )
|
# here I can write methods only for this repository
|
||||||
|
model = User
|
||||||
|
|
||||||
|
class BlogRepository(SQLAlchemyRepository):
|
||||||
|
model = Blog
|
||||||
|
|
||||||
|
class PostRepository(SQLAlchemyRepository):
|
||||||
|
model = Post
|
||||||
|
|
||||||
|
class LogRepository(SQLAlchemyRepository):
|
||||||
|
model = Log
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
# from src.adapters.database.repositories import (
|
from src.adapters.database.repositories import (
|
||||||
|
userRepository,
|
||||||
# )
|
BlogRepository,
|
||||||
|
PostRepository,
|
||||||
|
LogRepository
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RepositoriesGateway:
|
class RepositoriesGatewayDB1:
|
||||||
def __init__(self, session: AsyncSession):
|
def __init__(self, session: AsyncSession):
|
||||||
pass
|
self.user = userRepository(session)
|
||||||
|
self.blog = BlogRepository(session)
|
||||||
|
self.post = PostRepository(session)
|
||||||
|
|
||||||
|
|
||||||
|
class RepositoriesGatewayDB2:
|
||||||
|
def __init__(self, session: AsyncSession):
|
||||||
|
self.log = LogRepository(session)
|
||||||
|
20
src/api/create_dataset.py
Normal file
20
src/api/create_dataset.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends
|
||||||
|
|
||||||
|
from src.unit_of_work import UnitOfWork
|
||||||
|
|
||||||
|
dataset_router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@dataset_router.get("/comments", response_model=None)
|
||||||
|
async def get_database_comments(uow: Annotated[UnitOfWork, Depends(UnitOfWork)]):
|
||||||
|
pass
|
||||||
|
# async with uow:
|
||||||
|
# return await FavouriteService(uow, jwt_token).get_favourites(
|
||||||
|
# page=page, limit=limit
|
||||||
|
# )
|
||||||
|
|
||||||
|
@dataset_router.get("/general", response_model=None)
|
||||||
|
async def get_database_general(uow: Annotated[UnitOfWork, Depends(UnitOfWork)]):
|
||||||
|
pass
|
0
src/schemas/api/dataset_comments.py
Normal file
0
src/schemas/api/dataset_comments.py
Normal file
0
src/schemas/api/dataset_general.py
Normal file
0
src/schemas/api/dataset_general.py
Normal file
10
src/service/dataset_comments.py
Normal file
10
src/service/dataset_comments.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from src.unit_of_work import UnitOfWork
|
||||||
|
|
||||||
|
|
||||||
|
class DatasetCommentsService:
|
||||||
|
def __init__(self, uow: UnitOfWork):
|
||||||
|
self.uow = uow
|
||||||
|
|
||||||
|
async def get_dataset(self):
|
||||||
|
# data = await self.uow.repositories
|
||||||
|
pass
|
10
src/service/dataset_general.py
Normal file
10
src/service/dataset_general.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from src.unit_of_work import UnitOfWork
|
||||||
|
|
||||||
|
|
||||||
|
class DatasetGeneralService:
|
||||||
|
def __init__(self, uow: UnitOfWork):
|
||||||
|
self.uow = uow
|
||||||
|
|
||||||
|
async def get_dataset(self):
|
||||||
|
# data = await self.uow.repositories
|
||||||
|
pass
|
@ -1,44 +1,37 @@
|
|||||||
from asyncio import shield
|
from asyncio import shield
|
||||||
|
|
||||||
from src.adapters.database.repository_gateway import (
|
from src.adapters.database.repository_gateway import RepositoriesGatewayDB1, RepositoriesGatewayDB2
|
||||||
RepositoriesGateway,
|
from src.adapters.database.session import async_session_maker_db1, async_session_maker_db2
|
||||||
RepositoriesGatewayProtocol,
|
|
||||||
)
|
from src.utils.repository import _sentinel
|
||||||
from src.adapters.database.session import async_session_maker
|
|
||||||
from src.adapters.filestorage.repository import (
|
|
||||||
FileStorageProtocol,
|
|
||||||
FileStorageRepository,
|
|
||||||
)
|
|
||||||
from src.adapters.filestorage.session import s3_session_factory
|
|
||||||
from src.adapters.verification import VerificationGateway, VerificationProtocol
|
|
||||||
from src.utils.unit_of_work import UnitOfWorkProtocol
|
|
||||||
|
|
||||||
|
|
||||||
class UnitOfWork(UnitOfWorkProtocol):
|
class UnitOfWork:
|
||||||
file_storage: FileStorageProtocol
|
repositories = _sentinel
|
||||||
repositories: RepositoriesGatewayProtocol
|
|
||||||
verifications: VerificationProtocol
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.db_session_factory = async_session_maker
|
self.db1_session_factory = async_session_maker_db1
|
||||||
self.s3_session_facotry = s3_session_factory
|
self.db2_session_factory = async_session_maker_db2
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
self.db_session = self.db_session_factory()
|
self.db1_session = self.db1_session_factory()
|
||||||
self.s3_session = self.s3_session_facotry()
|
self.db2_session = self.db2_session_factory()
|
||||||
|
|
||||||
self.file_storage = FileStorageRepository(self.s3_session)
|
self.repositories_db1 = RepositoriesGatewayDB1(self.db1_session)
|
||||||
self.repositories = RepositoriesGateway(self.db_session)
|
self.repositories_db2 = RepositoriesGatewayDB2(self.db2_session)
|
||||||
self.verifications = VerificationGateway()
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def __aexit__(self, *args):
|
async def __aexit__(self, *args):
|
||||||
await self.rollback()
|
await self.rollback()
|
||||||
await shield(self.db_session.close())
|
await shield(self.db1_session.close())
|
||||||
|
await shield(self.db2_session.close())
|
||||||
|
|
||||||
async def commit(self):
|
async def commit(self):
|
||||||
await self.db_session.commit()
|
await self.db1_session.commit()
|
||||||
|
await self.db2_session.commit()
|
||||||
|
|
||||||
async def rollback(self):
|
async def rollback(self):
|
||||||
await self.db_session.rollback()
|
await self.db1_session.rollback()
|
||||||
|
await self.db2_session.rollback()
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
from datetime import datetime, timezone
|
|
||||||
from typing import Annotated
|
|
||||||
|
|
||||||
from fastapi import Depends
|
|
||||||
from fastapi.security import OAuth2PasswordBearer
|
|
||||||
|
|
||||||
from src.adapters.database.models.clients import ClientType
|
|
||||||
from src.adapters.jwt_token import JwtToken
|
|
||||||
|
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="authenticaition", auto_error=False)
|
|
||||||
|
|
||||||
|
|
||||||
async def provide_jwt_token(
|
|
||||||
encoded_token: Annotated[str | None, Depends(oauth2_scheme)] = None,
|
|
||||||
) -> JwtToken:
|
|
||||||
if encoded_token is None:
|
|
||||||
return JwtToken(
|
|
||||||
exp=datetime.now(timezone.utc), client_id=0, client_type=ClientType.individ
|
|
||||||
)
|
|
||||||
return JwtToken.decode(encoded_token)
|
|
@ -1,5 +0,0 @@
|
|||||||
from datetime import datetime, timezone
|
|
||||||
|
|
||||||
|
|
||||||
def utc_signed_now():
|
|
||||||
return datetime.now(timezone.utc)
|
|
@ -1,13 +0,0 @@
|
|||||||
import base64
|
|
||||||
import binascii
|
|
||||||
|
|
||||||
|
|
||||||
def is_valid_base64(value: str) -> bool:
|
|
||||||
try:
|
|
||||||
value = value.split(";base64,")[1]
|
|
||||||
base64.decodebytes(value.encode("ascii"))
|
|
||||||
return True
|
|
||||||
except binascii.Error:
|
|
||||||
return False
|
|
||||||
except IndexError:
|
|
||||||
return False
|
|
@ -1,9 +0,0 @@
|
|||||||
from abc import abstractmethod
|
|
||||||
from typing import Protocol
|
|
||||||
|
|
||||||
|
|
||||||
class VerificationProtocol(Protocol):
|
|
||||||
@abstractmethod
|
|
||||||
async def send_verification_code(self, phone_number: str) -> int:
|
|
||||||
"""Sends verification code to user and returns sended code"""
|
|
||||||
raise NotImplementedError
|
|
Loading…
x
Reference in New Issue
Block a user