Beispiel #1
0
async def delete_student_data(id: str):
    deleted_student = await delete_student(id)
    if deleted_student:
        return ResponseModel("Student with ID: {} removed".format(id),
                             "Student deleted successfully")
    return ErrorResponseModel("An error occurred", 404,
                              "Student with id {0} doesn't exist".format(id))
Beispiel #2
0
async def get_student_by_id(id):
    student = await retrive_student(id)
    if student:
        return ResponseModel(
            student, message=f"Successfully retrive the student of {id}")
    return ErrorResponseModel("An error occurred.", 404,
                              "Student doesn't exist.")
Beispiel #3
0
async def update_student_data(id: str, req: UpdateStudentModel = Body(...)):
    req = {k: v for k, v in req.dict().items() if v is not None}
    updated_student = await update_student(id, req)
    if updated_student:
        return ResponseModel("Student with ID {} has been updated".format(id),
                             "Student name updated succcesfully")
    return ErrorrResponseModel("An error occured", 404,
                               "Error updating student data")
Beispiel #4
0
async def delete_student_data(id: str):
    deleted_student = await delete_student(id)
    await aioproducer.send("pymongo",
                           json.dumps(deleted_student).encode('ascii'))
    if deleted_student:
        return ResponseModel("Student with ID: {} removed".format(id),
                             "Student deleted successfully")
    return ErrorResponseModel("An error occurred", 404,
                              "Student with id {0} doesn't exist".format(id))
Beispiel #5
0
async def update_student_data(id: str, req: UpdateStudentModel = Body(...)):
    req = {k: v for k, v in req.dict().items() if v is not None}
    updated_student = await update_student(id, req)
    await aioproducer.send("pymongo",
                           json.dumps(updated_student).encode('ascii'))
    if updated_student:
        return ResponseModel("Student with ID: {} removed".format(id),
                             "Student name updated successfully")
    return ErrorResponseModel("An error occured ", 404,
                              "There was an error updating the student data.")
Beispiel #6
0
async def update_student_data(id: str, req: UpdateStudentModel = Body(...)):
    req = {k: v for k, v in req.dict().items() if v is not None}
    updated_student = await update_student(id, req)
    if updated_student:
        return ResponseModel(
            "Student with ID: {} name update is successful".format(id),
            "Student name updated successfully",
        )
    return ErrorResponseModel(
        "An error occurred",
        404,
        "There was an error updating the student data.",
    )
Beispiel #7
0
async def add_student_data(student: StudentSchema = Body(...)):
    """When a request is sent to the endpoint, it stores a JSON-encoded
    request body in the variable 'student' before calling the 'add_student'
    database method and storing the response in the new_student variable.
    The response from the database is then returned via the ResponseModel.

    Args:
        student (StudentSchema, optional): [description]. Defaults to Body(...).

    Returns:
        [type]: [description]
    """
    student = jsonable_encoder(student)
    new_student = await add_student(student)
    return ResponseModel(new_student, "Student added successfully.")
Beispiel #8
0
async def get_students():
    students = await retrieve_students()
    if students:
        return ResponseModel(students, "Students data retrieved successfully")
    return ResponseModel(students, "Empty list returned")
Beispiel #9
0
async def add_student_data(student: StudentSchema = Body(...)):
    student = jsonable_encoder(student)
    new_student = await add_student(student)
    await aioproducer.send("pymongo", json.dumps(new_student).encode('ascii'))
    return ResponseModel(new_student, "Student added successfully.")
Beispiel #10
0
async def get_student_data(id):
    student = await retrieve_student(id)
    if student:
        return ResponseModel(student, "Student data retrieved successfully")
    return ErrorResponseModel("An error occurred.", 404, "Student doesn't exist.")
Beispiel #11
0
async def add_student_data(student: StudentSchema = Body(...)):
    student = jsonable_encoder(student)
    new_student = await add_student(student)
    return ResponseModel(new_student, "Student added successfully.")
Beispiel #12
0
async def get_student_data(id):
    student = await retrieve_student(id)
    if student:
        return ResponseModel(student, "student data retrieved")
    return ErrorrResponseModel("An error occured", 404,
                               "Student doesn't exist")
Beispiel #13
0
async def get_students():
    students = await retrieve_students()
    if students:
        return ResponseModel(students, "Student data retrieved")
    return ErrorrResponseModel("An error occured", 404, "Students don't exist")