def operation(id):

    # get student by id
    if request.method == 'GET':
        stu = student.query.get(id)
        return student_schema.jsonify(stu)

    # update student by id
    if request.method == 'PUT':
        stu = student.query.get(id)
        name = request.json['name']
        city = request.json['city']
        addr = request.json['addr']
        pin = request.json['pin']
        stu.name = name
        stu.city = city
        stu.addr = addr
        stu.pin = pin
        db.session.commit()
        return student_schema.jsonify(stu)

    # delete student by id
    if request.method == 'DELETE':

        std = student.query.get(id)
        db.session.delete(std)
        db.session.commit()
        return student_schema.jsonify(std)
def show_all():
    # create student
    if request.method == 'POST':

        name = request.json['name']
        city = request.json['city']
        addr = request.json['addr']
        pin = request.json['pin']
        new_student = student(name, city, addr, pin)
        db.session.add(new_student)
        db.session.commit()
        return student_schema.jsonify(new_student)

    # get all student
    if request.method == 'GET':
        all_students = student.query.all()
        result = students_schema.dump(all_students).data
        return jsonify(result)
예제 #3
0
def student_delete(id):
    student = StudentApi.delete_student(id)
    return student_schema.jsonify(student)
예제 #4
0
def student_update(id):

    student = StudentApi.query_student(id, request)
    return student_schema.jsonify(student)
예제 #5
0
def student_detail(id):
    student = StudentApi.get_student(id)
    return student_schema.jsonify(student)