Esempio n. 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))
Esempio n. 2
0
async def get_student_data(id):
    student = await retrieve_student(id)
    if student:
        return ResponseModel(student, 200,
                             "Student data retrieved successfully")
    return ErrorResponseModel("An error occurred.", 404,
                              "Student doesn't exist.")
Esempio n. 3
0
async def delete_student_data(id: str):
    deleted_student = await delete_student(id)
    if deleted_student:
        return ResponseModel(f'Student with ID:{id} removed',
                             'Student deleted successfully')
    return ErrorResponseModel('An error occurred', 404,
                              'Student with ID: {0} does not exist'.format(id))
Esempio n. 4
0
async def update_student_data(id: str, request: UpdateStudentModel = Body(...)):
    request = {k: v for k,v in request.dict().items() if v is not None}
    updated_student = await update_student(id, request)
    if updated_student:
        return ResponseModel(
            f"Student with ID: {id} name is updated successfully",
            "Success"
        )
    return ErrorResponseModel("An error occured", 404, "Something went wrong")
Esempio n. 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)
    if updated_student:
        return ResponseModel(
            f'Student with ID:{id} name update is successful ',
            'Student name updated successfully')
    return ErrorResponseModel('An error occuered', 404,
                              'There was an error updating the student data')
Esempio n. 6
0
async def delete_student_data(id: str):
    deleted_student = await delete_student(id)
    if deleted_student:
        return ResponseModel(
            f"Student with ID: {id} is deleted successfully",
            "Success"
        )
    return ErrorResponseModel(
        "An error occurred", 404, f"Student with ID: {id} does not exist"
    )
Esempio n. 7
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.",
    )
Esempio n. 8
0
async def get_student(id):
    student = await retrieve_student(id)
    if student:
        return ResponseModel(student, "Studend data retrieved successfully")
    return ErrorResponseModel("An error occured", 404, "There is no student with that id")
Esempio n. 9
0
async def get_students():
    students = await retrieve_students()
    if students:
        return ResponseModel(students, "Studens data retrieved successfully")
    return ResponseModel(students, "Empty List Returned")\
Esempio n. 10
0
async def add_student_data(student: StudentShema = Body(...)):
    student = jsonable_encoder(student)
    new_student = await add_student(student)
    return ResponseModel(new_student, "Student added successfully")
Esempio n. 11
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 occured.', 404,
                              'Student does not exist')
Esempio n. 12
0
async def get_students():
    students = await retrieve_students()
    if students:
        return ResponseModel(students, 'Students data retrieved successfully')
    return ResponseModel(students, 'Empty list returned')