доделали регистрацию
This commit is contained in:
parent
3d26a7f212
commit
9187518c8b
@ -1,6 +1,6 @@
|
||||
from select import select
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.domain.models import Role
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from select import select
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.domain.models import Team
|
||||
|
||||
27
API/app/contollers/register_controller.py
Normal file
27
API/app/contollers/register_controller.py
Normal file
@ -0,0 +1,27 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi.params import Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.database.session import get_db
|
||||
from app.domain.entities.register import RegisterEntity
|
||||
from app.domain.entities.user import UserEntity
|
||||
from app.infrastructure.users_service import UsersService
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post(
|
||||
'/',
|
||||
response_model=Optional[UserEntity],
|
||||
summary='User Registration',
|
||||
description='Performs user registration in the system',
|
||||
)
|
||||
async def register_user(
|
||||
user_data: RegisterEntity,
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
users_service = UsersService(db)
|
||||
user = await users_service.register_user(user_data)
|
||||
return user
|
||||
@ -139,7 +139,7 @@ def upgrade() -> None:
|
||||
)
|
||||
op.create_table('users',
|
||||
sa.Column('login', sa.VARCHAR(length=150), nullable=False),
|
||||
sa.Column('password', sa.VARCHAR(length=150), nullable=False),
|
||||
sa.Column('password', sa.VARCHAR(), nullable=False),
|
||||
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
|
||||
15
API/app/database/session.py
Normal file
15
API/app/database/session.py
Normal file
@ -0,0 +1,15 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from app.settings import settings
|
||||
|
||||
engine = create_async_engine(settings.DATABASE_URL, echo=False)
|
||||
|
||||
async_session_maker = sessionmaker(
|
||||
bind=engine, class_=AsyncSession, expire_on_commit=False
|
||||
)
|
||||
|
||||
|
||||
async def get_db():
|
||||
async with async_session_maker() as session:
|
||||
yield session
|
||||
@ -6,6 +6,7 @@ from app.domain.entities.profile import ProfileEntity
|
||||
|
||||
class UserEntity(BaseUserEntity):
|
||||
id: Optional[int] = None
|
||||
password: Optional[str] = None
|
||||
|
||||
profile_id: int
|
||||
|
||||
|
||||
@ -9,4 +9,4 @@ class ContestStatus(AdvancedBaseModel):
|
||||
|
||||
title = Column(VARCHAR(150), unique=True, nullable=False)
|
||||
|
||||
contest = relationship("Contest", back_populates="status")
|
||||
contests = relationship("Contest", back_populates="status")
|
||||
|
||||
@ -10,6 +10,6 @@ class Project(AdvancedBaseModel):
|
||||
description = Column(VARCHAR(150))
|
||||
repository_url = Column(String, nullable=False)
|
||||
|
||||
contest = relationship("Contest", back_populates="project")
|
||||
contests = relationship("Contest", back_populates="project")
|
||||
files = relationship("ProjectFile", back_populates="project")
|
||||
members = relationship("ProjectMember", back_populates="project")
|
||||
|
||||
@ -12,4 +12,4 @@ class Team(AdvancedBaseModel):
|
||||
logo = Column(String)
|
||||
git_url = Column(String)
|
||||
|
||||
profile = relationship("Profile", back_populates="team")
|
||||
profiles = relationship("Profile", back_populates="team")
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, VARCHAR, ForeignKey, Integer
|
||||
from sqlalchemy import Column, VARCHAR, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
||||
@ -9,7 +9,7 @@ class User(AdvancedBaseModel):
|
||||
__tablename__ = 'users'
|
||||
|
||||
login = Column(VARCHAR(150), unique=True, nullable=False)
|
||||
password = Column(VARCHAR(150), nullable=False)
|
||||
password = Column(String, nullable=False)
|
||||
|
||||
profile_id = Column(Integer, ForeignKey('profiles.id'), nullable=False)
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ from app.application.profiles_repository import ProfilesRepository
|
||||
from app.application.roles_repository import RolesRepository
|
||||
from app.application.teams_repository import TeamsRepository
|
||||
from app.application.users_repository import UsersRepository
|
||||
from app.domain.entities.profile import ProfileEntity
|
||||
from app.domain.entities.register import RegisterEntity
|
||||
from app.domain.entities.user import UserEntity
|
||||
from app.domain.models import User, Profile
|
||||
@ -40,7 +41,10 @@ class UsersService:
|
||||
user_model.profile_id = profile_model.id
|
||||
user_model = await self.users_repository.create(user_model)
|
||||
|
||||
return UserEntity
|
||||
user_entity = self.user_model_to_entity(user_model)
|
||||
user_entity.profile = self.profile_model_to_entity(profile_model)
|
||||
|
||||
return user_entity
|
||||
|
||||
@staticmethod
|
||||
def is_strong_password(password):
|
||||
@ -85,9 +89,24 @@ class UsersService:
|
||||
|
||||
return user, pofile
|
||||
|
||||
@staticmethod
|
||||
def profile_model_to_entity(profile_model: Profile) -> ProfileEntity:
|
||||
return ProfileEntity(
|
||||
id=profile_model.id,
|
||||
first_name=profile_model.first_name,
|
||||
last_name=profile_model.last_name,
|
||||
patronymic=profile_model.patronymic,
|
||||
birthday=profile_model.birthday,
|
||||
email=profile_model.email,
|
||||
phone=profile_model.phone,
|
||||
role_id=profile_model.role_id,
|
||||
team_id=profile_model.team_id,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def user_model_to_entity(user_model: User) -> UserEntity:
|
||||
return UserEntity(
|
||||
id=user_model.id,
|
||||
login=user_model.login,
|
||||
profile_id=user_model.profile_id,
|
||||
)
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.contollers.register_controller import router as register_router
|
||||
from app.settings import settings
|
||||
|
||||
|
||||
def start_app():
|
||||
api_app = FastAPI()
|
||||
|
||||
@ -12,10 +16,14 @@ def start_app():
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
api_app.include_router(register_router, prefix=f'{settings.PREFIX}/register', tags=['register'])
|
||||
|
||||
return api_app
|
||||
|
||||
|
||||
app = start_app()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"message": "Hello API"}
|
||||
return {"message": "Hello API"}
|
||||
|
||||
@ -4,6 +4,7 @@ from pydantic_settings import BaseSettings
|
||||
class Settings(BaseSettings):
|
||||
DATABASE_URL: str
|
||||
SECRET_KEY: str
|
||||
PREFIX: str = ''
|
||||
|
||||
class Config:
|
||||
env_file = '.env'
|
||||
|
||||
BIN
API/req.txt
BIN
API/req.txt
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user