This commit is contained in:
adam-skowronek 2022-06-13 20:13:30 +02:00
commit 5a49e87a63

View File

@ -50,6 +50,13 @@ def create_group(data: dict) -> dict:
# elif result <= 0: # elif 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")
project_supervisor = ProjectSupervisor.query.filter_by(id=project_supervisor_id).first()
if project_supervisor is None:
abort(400, "Project Supervisor with id {project_supervisor_id} doesnt exist")
elif project_supervisor.limit_group == project_supervisor.count_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)
students_without_groups = db.session.query(Student).join(Group, isouter=True) \ students_without_groups = db.session.query(Student).join(Group, isouter=True) \
@ -59,6 +66,7 @@ def create_group(data: dict) -> dict:
abort(400, "One or more students have already belonged to group!") abort(400, "One or more students have already belonged to group!")
students = db.session.query(Student).filter(Student.index.in_(students_indexes)).all() students = db.session.query(Student).filter(Student.index.in_(students_indexes)).all()
project_supervisor.count_groups += 1
for student in students: for student in students:
student.group_id = group.id student.group_id = group.id