Skip to content

Commit

Permalink
Merge pull request #78 from w1tnessbtwwwww/backend
Browse files Browse the repository at this point in the history
Backend
  • Loading branch information
w1tnessbtwwwww authored Jan 9, 2025
2 parents af04258 + 27f658d commit 5a360c1
Show file tree
Hide file tree
Showing 34 changed files with 290 additions and 140 deletions.
2 changes: 2 additions & 0 deletions SpeedSolverBackend/SpeedSolverAPI/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ rev:
mig:
poetry run alembic upgrade head

kill:
taskkill /f /im python.exe
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""empty message
Revision ID: 6643f9ccf5d9
Revises: c06adcf3e66f
Create Date: 2025-01-09 12:39:04.015173
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '6643f9ccf5d9'
down_revision: Union[str, None] = 'c06adcf3e66f'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('projects',
sa.Column('projectId', sa.UUID(), nullable=False),
sa.Column('title', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('projectId')
)
op.add_column('team_projects', sa.Column('projectId', sa.UUID(), nullable=False))
op.drop_constraint('team_projects_project_title_key', 'team_projects', type_='unique')
op.create_foreign_key(None, 'team_projects', 'projects', ['projectId'], ['projectId'])
op.drop_column('team_projects', 'project_description')
op.drop_column('team_projects', 'project_title')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('team_projects', sa.Column('project_title', sa.VARCHAR(), autoincrement=False, nullable=False))
op.add_column('team_projects', sa.Column('project_description', sa.VARCHAR(), autoincrement=False, nullable=True))
op.drop_constraint(None, 'team_projects', type_='foreignkey')
op.create_unique_constraint('team_projects_project_title_key', 'team_projects', ['project_title'])
op.drop_column('team_projects', 'projectId')
op.drop_table('projects')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""empty message
Revision ID: 6452a4cc13cd
Revises: 26e74bb7d56d
Create Date: 2025-01-02 17:26:10.345848
Revision ID: 96db638aa74c
Revises: 6643f9ccf5d9
Create Date: 2025-01-09 12:41:37.424427
"""
from typing import Sequence, Union
Expand All @@ -12,19 +12,21 @@


# revision identifiers, used by Alembic.
revision: str = '6452a4cc13cd'
down_revision: Union[str, None] = '26e74bb7d56d'
revision: str = '96db638aa74c'
down_revision: Union[str, None] = '6643f9ccf5d9'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('email_verifications', sa.Column('created_at', sa.DateTime(), nullable=False))
op.add_column('objectives', sa.Column('projectId', sa.UUID(), nullable=False))
op.create_foreign_key(None, 'objectives', 'projects', ['projectId'], ['projectId'], ondelete='CASCADE')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('email_verifications', 'created_at')
op.drop_constraint(None, 'objectives', type_='foreignkey')
op.drop_column('objectives', 'projectId')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""empty message
Revision ID: 26e74bb7d56d
Revision ID: c06adcf3e66f
Revises:
Create Date: 2024-12-22 16:00:34.382467
Create Date: 2025-01-09 12:38:12.616311
"""
from typing import Sequence, Union
Expand All @@ -12,7 +12,7 @@


# revision identifiers, used by Alembic.
revision: str = '26e74bb7d56d'
revision: str = 'c06adcf3e66f'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Expand All @@ -28,12 +28,6 @@ def upgrade() -> None:
sa.ForeignKeyConstraint(['parent_objectiveId'], ['objectives.objectiveId'], ),
sa.PrimaryKeyConstraint('objectiveId')
)
op.create_table('projects',
sa.Column('projectId', sa.UUID(), nullable=False),
sa.Column('title', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('projectId')
)
op.create_table('users',
sa.Column('userId', sa.UUID(), nullable=False),
sa.Column('email', sa.String(), nullable=True),
Expand All @@ -47,9 +41,9 @@ def upgrade() -> None:
sa.Column('verification_id', sa.UUID(), nullable=False),
sa.Column('userId', sa.UUID(), nullable=False),
sa.Column('verification_code', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['userId'], ['users.userId'], ),
sa.PrimaryKeyConstraint('verification_id'),
sa.UniqueConstraint('userId')
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['userId'], ['users.userId'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('verification_id')
)
op.create_table('organizations',
sa.Column('organizationId', sa.UUID(), nullable=False),
Expand All @@ -66,7 +60,7 @@ def upgrade() -> None:
sa.Column('patronymic', sa.String(), nullable=True),
sa.Column('birthdate', sa.Date(), nullable=True),
sa.Column('userId', sa.UUID(), nullable=False),
sa.ForeignKeyConstraint(['userId'], ['users.userId'], ),
sa.ForeignKeyConstraint(['userId'], ['users.userId'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('userProfileId')
)
op.create_table('teams',
Expand Down Expand Up @@ -100,10 +94,11 @@ def upgrade() -> None:
op.create_table('team_projects',
sa.Column('teamProjectId', sa.UUID(), nullable=False),
sa.Column('teamId', sa.UUID(), nullable=False),
sa.Column('projectId', sa.UUID(), nullable=False),
sa.ForeignKeyConstraint(['projectId'], ['projects.projectId'], ),
sa.Column('project_title', sa.String(), nullable=False),
sa.Column('project_description', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['teamId'], ['teams.teamId'], ),
sa.PrimaryKeyConstraint('teamProjectId')
sa.PrimaryKeyConstraint('teamProjectId'),
sa.UniqueConstraint('project_title')
)
# ### end Alembic commands ###

Expand All @@ -118,6 +113,5 @@ def downgrade() -> None:
op.drop_table('organizations')
op.drop_table('email_verifications')
op.drop_table('users')
op.drop_table('projects')
op.drop_table('objectives')
# ### end Alembic commands ###

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class Objective(Base):
title: Mapped[str] = mapped_column()
description: Mapped[str] = mapped_column(nullable=True)
parent_objectiveId: Mapped[UUID] = mapped_column(ForeignKey("objectives.objectiveId"), nullable=True)

projectId: Mapped[UUID] = mapped_column(UUID, ForeignKey("projects.projectId", ondelete='CASCADE'), nullable=False)

project: Mapped["Project"] = relationship("Project", back_populates="objectives")
parent_objective: Mapped["Objective"] = relationship("Objective", back_populates="child_objectives", remote_side=[objectiveId])
child_objectives: Mapped[list["Objective"]] = relationship("Objective", back_populates="parent_objective")



class Organization(Base):
Expand All @@ -36,6 +39,8 @@ class Project(Base):
title: Mapped[str] = mapped_column()
description: Mapped[str] = mapped_column(nullable=True)

objectives: Mapped[List["Objective"]] = relationship("Objective", back_populates="project")


class TeamMember(Base):
__tablename__ = "team_members"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import CursorResult, and_, delete, select, update, insert

from app.routing.security.hasher import verify_password
from app.security.hasher import verify_password

from app.utils.result import *
from app.utils.logger.telegram_bot.telegram_logger import logger
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from sqlalchemy import and_, select
from app.database.abstract.abc_repo import AbstractRepository
from app.database.models.models import Project
from app.database.repo.team_projects_repository import TeamProjectRepository
from app.utils.result import Result, err, success
from app.utils.logger.telegram_bot.telegram_logger import logger


class ProjectRepository(AbstractRepository):
model = Project


async def create_project(self, binded_teamId: str, title: str, description: str) -> Result[Project]:

team_project_repository = TeamProjectRepository(self._session)


project_query = (
select(self.model)
.where(
and_(
self.model.title == title,
self.model.description == description
)
)
)

project_result = await self._session.execute(project_query)
projects = project_result.scalars().all()


team_projects_query = (
select(team_project_repository.model)
.where(
team_project_repository.model.teamId == binded_teamId
)
)

team_projects_result = await self._session.execute(team_projects_query)
team_projects = team_projects_result.scalars().all()




Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from app.database.abstract.abc_repo import AbstractRepository
from app.database.models.models import TeamProject

class TeamProjectRepository(AbstractRepository):
model = TeamProject


Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from app.database.models.models import Team
from sqlalchemy import select, update, delete, insert, and_, or_
from app.utils.result import Result, err, success

from app.utils.logger.telegram_bot.telegram_logger import logger
class TeamRepository(AbstractRepository):
model: Team = Team

Expand Down Expand Up @@ -32,12 +34,24 @@ async def create_team(self,

return success(value = await self.create(title=title, description=description, leaderId=leaderId, organizationId=organizationId))


async def delete_team(self, teamId: str, leaderId: str) -> Result[int]:
query = delete(self.model).where(and_(self.model.teamId == teamId, self.model.leaderId == leaderId))
try:
result = await self._session.execute(query)
await self.commit()
except Exception as e:
logger.error(e)
return err("Внутренняя ошибка сервера. Информация уже отправлена разработчику.")
return success(result.rowcount)

async def update_team(self,
teamId: str,
leaderId: str,
new_title: str = None,
new_description: str = None,
new_leader_id: str = None
new_leader_id: str = None,
new_organization_id: str = None
) -> Result[Team]:

team: Team = await self.get_by_filter_one(teamId=teamId)
Expand All @@ -50,14 +64,14 @@ async def update_team(self,
)).values(
title = new_title if new_title else team.title,
description = new_description if new_description else team.description,
leaderId = new_leader_id if new_leader_id else team.leaderId
leaderId = new_leader_id if new_leader_id else team.leaderId,
organizationId = new_organization_id if new_organization_id else team.organizationId
)
)
try:
result = await self._session.execute(query)
await self.commit()
except Exception as e:
return err(str(e))
return success(value={
"msg": "success"
})
logger.error(e)
return err("Внутренняя ошибка сервера. Информация уже отправлена разработчику.")
return success(result.scalars().first())
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sqlalchemy.ext.asyncio import AsyncSession

from app.routing.security.hasher import verify_password
from app.security.hasher import verify_password
from app.utils.result import *
from ..abstract.abc_repo import AbstractRepository
from app.database.models.models import UserProfile
Expand Down
Loading

0 comments on commit 5a360c1

Please sign in to comment.