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))
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.")
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))
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")
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')
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" )
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.", )
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")
async def get_students(): students = await retrieve_students() if students: return ResponseModel(students, "Studens data retrieved successfully") return ResponseModel(students, "Empty List Returned")\
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")
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')
async def get_students(): students = await retrieve_students() if students: return ResponseModel(students, 'Students data retrieved successfully') return ResponseModel(students, 'Empty list returned')