This commit is contained in:
adam-skowronek 2022-06-13 21:26:28 +02:00
commit 56853fb906

View File

@ -38,23 +38,18 @@ def create_group(data: dict) -> dict:
students_indexes = data['students'] students_indexes = data['students']
project_supervisor_id = data['project_supervisor_id'] project_supervisor_id = data['project_supervisor_id']
# can assign a new group to project_supervisor
# nie działa to poprawnie
# result = db.session.query(ProjectSupervisor.count_groups - db.func.count(ProjectSupervisor.id)). \
# join(Group).filter(ProjectSupervisor.id == project_supervisor_id). \
# group_by(ProjectSupervisor.id).scalar()
# if result is None:
# abort(400, "Project Supervisor doesnt exist")
# elif result <= 0:
# abort(400, "Can't create new group, project supervisor achieved a limit of groups")
project_supervisor = ProjectSupervisor.query.filter_by(id=project_supervisor_id).first() project_supervisor = ProjectSupervisor.query.filter_by(id=project_supervisor_id).first()
if project_supervisor is None: if project_supervisor is None:
abort(400, "Project Supervisor with id {project_supervisor_id} doesnt exist") abort(400, f"Project Supervisor with id {project_supervisor_id} doesnt exist")
elif project_supervisor.limit_group == project_supervisor.count_groups: elif project_supervisor.limit_group < len(students_indexes):
abort(400, f"Too much students you want add to group, "
f"this group can have only {project_supervisor.limit_group} students")
result = db.session.query(ProjectSupervisor.count_groups - db.func.count(ProjectSupervisor.id)).join(Group).filter(
ProjectSupervisor.id == project_supervisor_id).group_by(ProjectSupervisor.id).scalar()
if result is not None and result <= 0:
abort(400, "Can't create new group, project supervisor achieved a limit of groups") abort(400, "Can't create new group, project supervisor achieved a limit of groups")
group = Group(name=name, project_supervisor_id=project_supervisor_id) group = Group(name=name, project_supervisor_id=project_supervisor_id)