from flask import abort from apiflask import APIBlueprint from flask_sqlalchemy import get_debug_queries from ...dependencies import db, ma bp = APIBlueprint("groups", __name__, url_prefix="/groups") @bp.route("/", methods=["GET"]) def list_groups(): """ groups = (QUERY: get all groups(includes supervisor project) and filter by name) # paginate groups return groups """ @bp.route("/", methods=["POST"]) def create_group() -> dict: """ Create group: body: { name:"system pri", project_supervisor: id students:[index1, index2] } 1. if (QUERY: check if all students exist in database): abort() project_supervisor = (QUERY: get project_supervisor by id) 2. if project_supervisor is None: abort() 3. if (QUERY: check if project_supervisor can have new group -> (limit_group - count(groups.id)) > 0): abort() 4. If no errors, you can create a group return message """ @bp.route("//", methods=["GET"]) def detail_group(id: int): """ group = (QUERY: get group by id) if (group is none): abort() return group """ @bp.route("//", methods=["DELETE"]) def delete_group(id: int): """ group = (QUERY: get group by id) if (group is none): abort() delete group return message """ @bp.route("//name", methods=["PUT"]) def edit_group_name(id: int): """ body: { name: "name_group" } group = (QUERY: get group by id) if (group is none): abort() update group return message """ @bp.route("//project_supervisor", methods=["PUT"]) def edit_group_project_supervisor(id: int): """ body: { project_supervisor_id: 23 } group = (QUERY: get group by id) if (group is none): abort() project_supervisor = (QUERY: get project_supervisor by id) if project_supervisor is None: abort() if (QUERY: check if project_supervisor can be assigned to new group -> (limit_group - count(groups.id)) > 0 ): abort() update group return message """ @bp.route("//students", methods=["PUT"]) def edit_group_student(id: int): """ body: { index: 344331 } group = (QUERY: get group by id) if (group is none): abort() student = (QUERY: get student by index) if student is None: abort() if (QUERY: check if the student's have a group in database): abort() update group return message """