Esempio n. 1
0
def delete_school(school_id):
    """
    delete school by ID
    :param school_id:
    :return:
    """
    try:
        current_app.logger.info("Delete school id: {}".format(school_id))
        school_delete_status = False
        school = school_service.get_school_by_id(school_id)

        if len(school) == 0:
            current_app.logger.error(
                "No school id to delete: {}".format(school_id))
            return jsonify({"errors": ["No school id to delete"]}), 404

        if school_service.delete_school_by_id(school_id):
            school_delete_status = address_service.delete_address_by_id(
                school["address"]["id"])
        else:
            current_app.logger.error(
                "Fail to delete school id: {}".format(school_id))

        return jsonify({"status": school_delete_status}), 200

    except SQLCustomError as error:
        current_app.logger.error(
            "Fail to delete school_id: {}".format(school_id))
        return jsonify({"errors": [error.__dict__]}), 400
Esempio n. 2
0
def delete_students(student_id: int):
    """
    delete student by ID
    :param student_id:
    :return:
    """
    try:
        current_app.logger.info("Delete student id: {}".format(student_id))
        student_delete_status = False
        student = student_service.get_student_by_id(student_id)
        if student_service.delete_student_by_id(student_id):
            if student.get("photo") and student_service.delete_file(
                    student.get("photo")):
                current_app.logger.info(
                    "Student photo exists and delete the photo in s3")
            else:
                current_app.logger.warning(
                    "No photo or delete the photo in s3")
            student_delete_status = address_service.delete_address_by_id(
                student["address"]["id"])
        return jsonify({"status": student_delete_status}), 200
    except SQLCustomError as error:
        current_app.logger.error(
            "Fail to delete student_id: %s".format(student_id))
        return jsonify({"errors": [error.__dict__]}), 400
Esempio n. 3
0
def delete_students(student_id: int):
    """
    delete student  by ID
    :param student_id:
    :return:
    """
    try:
        current_app.logger.info("Delete student id: {}".format(student_id))
        student_delete_status = False
        student = student_service.get_student_by_id(student_id)
        if student_service.delete_student_by_id(student_id):
            student_delete_status = address_service.delete_address_by_id(
                student["address"]["id"])
        return jsonify({"status": student_delete_status}), 200
    except SQLCustomError as error:
        current_app.logger.error(
            "Fail to delete student_id: %s".format(student_id))
        return jsonify({"errors": [error.__dict__]}), 400