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:
|
||||
abort(400, f"Group with id {id} doesn't exist!")
|
||||
|
||||
group_query.update(group)
|
||||
group_query.update(data)
|
||||
db.session.commit()
|
||||
return {"message": "Group was updated!"}
|
||||
|
@ -3,9 +3,10 @@ from apiflask import APIBlueprint
|
||||
from flask_sqlalchemy import get_debug_queries
|
||||
|
||||
from ...project_supervisor.models import ProjectSupervisor
|
||||
from ...students.models import Group
|
||||
from ..schemas import ProjectSupervisorSchema, ProjectSupervisorEditSchema, ProjectSupervisorsPaginationSchema, \
|
||||
ProjectSupervisorCreateSchema, MessageSchema, FileSchema, ProjectSupervisorQuerySchema
|
||||
from ...dependencies import db, ma
|
||||
ProjectSupervisorCreateSchema, MessageSchema, ProjectSupervisorQuerySchema
|
||||
from ...dependencies import db
|
||||
from ...base.utils import paginate_models
|
||||
|
||||
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:
|
||||
first_name = data['first_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()
|
||||
if project_supervisor is not None:
|
||||
abort(400, "Project Supervisor has already exists!")
|
||||
|
||||
project_supervisor = ProjectSupervisor(first_name=first_name,
|
||||
last_name = last_name,
|
||||
email = email,
|
||||
limit_group = limit_group,
|
||||
mode = mode)
|
||||
project_supervisor = ProjectSupervisor(**data)
|
||||
|
||||
db.session.add(project_supervisor)
|
||||
db.session.commit()
|
||||
@ -75,7 +69,9 @@ def delete_project_supervisor(id: int) -> dict:
|
||||
if project_supervisor is None:
|
||||
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!")
|
||||
|
||||
db.session.delete(project_supervisor)
|
||||
@ -96,6 +92,6 @@ def edit_project_supervisor(id: int, data: dict) -> dict:
|
||||
if project_supervisor is None:
|
||||
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()
|
||||
return {"message": "Project Supervisor was updated!"}
|
||||
|
Loading…
Reference in New Issue
Block a user