Ejemplo n.º 1
0
 def get(self):
     users_schema = UserSchema(many=True)
     try:
         users = User.retrieve_all()
     except Exception as e:
         return jsonify(error=str(e))
     else:
         return users_schema.jsonify(users).json, 200
Ejemplo n.º 2
0
        def get(self, id):
            user_schema = UserSchema()
            try:
                data = {'id': id}
                user = User.retrieve_by(**data)
                if not user:
                    raise Exception(f'There are not user ID {id}')

            except Exception as e:
                return jsonify(error=str(e))

            else:
                return user_schema.jsonify(user).json, 200
Ejemplo n.º 3
0
        def post(self):
            user_schema = UserSchema()
            try:
                data_json = request.json
                if not data_json:
                    raise Exception('The request does not have json data.')

                user = User.create(**data_json)

            except Exception as e:
                return jsonify(error=str(e))

            else:
                return user_schema.jsonify(user).json, 201
Ejemplo n.º 4
0
        def put(self, id):
            user_schema = UserSchema()
            try:
                data = {'id': id}
                user = User.retrieve_by(**data)
                if not user:
                    raise Exception(f'There are not user ID {id}')

                data_json = request.json
                if not data_json:
                    raise Exception('The request does not have json data.')

                user.update(**data_json)

            except Exception as e:
                return jsonify(error=str(e))

            else:
                return user_schema.jsonify(user).json, 200
Ejemplo n.º 5
0
def me():
    me_schema = UserSchema(exclude=('inbox.content', 'inbox.updated_at',
                                    'outbox.updated_at', 'outbox.content',
                                    'outbox.receiver.id', 'inbox.sender.id',
                                    'updated_at'))
    return me_schema.jsonify(g.current_user)