update create group endpoint for coordinator view - check limit of students
This commit is contained in:
parent
5a49e87a63
commit
5d5353eed1
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user