def get(self, id=None): if id: try: user = User.objects(id=id).first() except MongoValidationError as error: abort(400, f"{error}") return UserSchema().dump(user) else: users = User.objects() return UserSchema().dump(users, many=True)
def put(self, id): try: data = UserSchema().load(request.get_json()) update_user(data, id) # method to update fields except (MarshmallowValidationError, MongoValidationError) as error: abort(400, f"{error}") new_user = User.objects(id=id) return UserSchema().dump(new_user, many=True)