update: edit and delete project_supervisor endpoints and edit groups endpoints for coordinator view
This commit is contained in:
parent
bb070977f9
commit
f0f14d7b1c
@ -100,6 +100,6 @@ def edit_group(id: int, data: dict) -> dict:
|
|||||||
if group is None:
|
if group is None:
|
||||||
abort(400, f"Group with id {id} doesn't exist!")
|
abort(400, f"Group with id {id} doesn't exist!")
|
||||||
|
|
||||||
group_query.update(group)
|
group_query.update(data)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return {"message": "Group was updated!"}
|
return {"message": "Group was updated!"}
|
||||||
|
@ -3,9 +3,10 @@ from apiflask import APIBlueprint
|
|||||||
from flask_sqlalchemy import get_debug_queries
|
from flask_sqlalchemy import get_debug_queries
|
||||||
|
|
||||||
from ...project_supervisor.models import ProjectSupervisor
|
from ...project_supervisor.models import ProjectSupervisor
|
||||||
|
from ...students.models import Group
|
||||||
from ..schemas import ProjectSupervisorSchema, ProjectSupervisorEditSchema, ProjectSupervisorsPaginationSchema, \
|
from ..schemas import ProjectSupervisorSchema, ProjectSupervisorEditSchema, ProjectSupervisorsPaginationSchema, \
|
||||||
ProjectSupervisorCreateSchema, MessageSchema, FileSchema, ProjectSupervisorQuerySchema
|
ProjectSupervisorCreateSchema, MessageSchema, ProjectSupervisorQuerySchema
|
||||||
from ...dependencies import db, ma
|
from ...dependencies import db
|
||||||
from ...base.utils import paginate_models
|
from ...base.utils import paginate_models
|
||||||
|
|
||||||
bp = APIBlueprint("project_supervisor", __name__, url_prefix="/project_supervisor")
|
bp = APIBlueprint("project_supervisor", __name__, url_prefix="/project_supervisor")
|
||||||
@ -39,19 +40,12 @@ def list_project_supervisors(query: dict) -> dict:
|
|||||||
def create_project_supervisor(data: dict) -> dict:
|
def create_project_supervisor(data: dict) -> dict:
|
||||||
first_name = data['first_name']
|
first_name = data['first_name']
|
||||||
last_name = data['last_name']
|
last_name = data['last_name']
|
||||||
email = data['email']
|
|
||||||
limit_group = data['limit_group']
|
|
||||||
mode = data['mode']
|
|
||||||
|
|
||||||
project_supervisor = ProjectSupervisor.query.filter(first_name=first_name).filter(last_name=last_name).first()
|
project_supervisor = ProjectSupervisor.query.filter(first_name=first_name).filter(last_name=last_name).first()
|
||||||
if project_supervisor is not None:
|
if project_supervisor is not None:
|
||||||
abort(400, "Project Supervisor has already exists!")
|
abort(400, "Project Supervisor has already exists!")
|
||||||
|
|
||||||
project_supervisor = ProjectSupervisor(first_name=first_name,
|
project_supervisor = ProjectSupervisor(**data)
|
||||||
last_name = last_name,
|
|
||||||
email = email,
|
|
||||||
limit_group = limit_group,
|
|
||||||
mode = mode)
|
|
||||||
|
|
||||||
db.session.add(project_supervisor)
|
db.session.add(project_supervisor)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@ -74,8 +68,10 @@ def delete_project_supervisor(id: int) -> dict:
|
|||||||
project_supervisor = ProjectSupervisor.query.filter_by(id=id).first()
|
project_supervisor = ProjectSupervisor.query.filter_by(id=id).first()
|
||||||
if project_supervisor is None:
|
if project_supervisor is None:
|
||||||
abort(400, f"Project Supervisor with id {id} doesn't exist!")
|
abort(400, f"Project Supervisor with id {id} doesn't exist!")
|
||||||
|
|
||||||
if project_supervisor.count_groups > 0:
|
count_groups = db.session.query(db.func.count(ProjectSupervisor.id)).join(Group).\
|
||||||
|
filter(ProjectSupervisor.id == id).group_by(ProjectSupervisor.id).scalar()
|
||||||
|
if count_groups > 0:
|
||||||
abort(400, f"Project Supervisor with id {id} has gropus!")
|
abort(400, f"Project Supervisor with id {id} has gropus!")
|
||||||
|
|
||||||
db.session.delete(project_supervisor)
|
db.session.delete(project_supervisor)
|
||||||
@ -96,6 +92,6 @@ def edit_project_supervisor(id: int, data: dict) -> dict:
|
|||||||
if project_supervisor is None:
|
if project_supervisor is None:
|
||||||
abort(400, f"Project Supervisor with id {id} doesn't exist!")
|
abort(400, f"Project Supervisor with id {id} doesn't exist!")
|
||||||
|
|
||||||
project_supervisor_query.update(project_supervisor)
|
project_supervisor_query.update(data)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return {"message": "Project Supervisor was updated!"}
|
return {"message": "Project Supervisor was updated!"}
|
||||||
|
Loading…
Reference in New Issue
Block a user