Ejemplo n.º 1
0
    def post(self):
        args = request.get_json()
        db = get_db()
        id_ = len(db['albums']) + 1
        db['albums'].append({'id': id_, **args})

        return {'id': id_}, 201
Ejemplo n.º 2
0
    def delete(self, post_id):
        db = get_db()

        try:
            del db['posts'][post_id - 1]
            return {}, 204
        except IndexError:
            return 'Not found', 404
Ejemplo n.º 3
0
 def get(self):
     db = get_db()
     args = request.args.get('userId')
     if args is not None:
         comments = [c for c in db['albums'] if c['userId'] == int(args)]
         return jsonify(comments) if comments else Response('Not Found',
                                                            status=404)
     return db['posts']
Ejemplo n.º 4
0
 def get(self):
     db = get_db()
     args = request.args.get('userId')
     if args is not None:
         albums = [a for a in db['albums'] if
                   a['userId'] == int(args)]
         return jsonify(albums) if albums else Response('Not Found',
                                                        status=404)
     return db['albums']
Ejemplo n.º 5
0
    def patch(self, post_id):
        post = request.get_json()
        db = get_db()

        try:
            db['posts'][post_id - 1].update(post)
            return {}, 204

        except IndexError:
            return 'Not found', 404
Ejemplo n.º 6
0
    def put(self, post_id):
        post = request.get_json()
        db = get_db()

        try:
            db['posts'][post_id - 1] = post
            print(db['posts'][post_id - 1])
            return {}, 204
        except IndexError:
            return 'Not found', 404
Ejemplo n.º 7
0
 def get(self, post_id):
     db = get_db()
     comments = [c for c in db['comments'] if c['postId'] == int(post_id)]
     return jsonify(comments) if comments else Response('Not Found',
                                                        status=404)
Ejemplo n.º 8
0
 def get(self, post_id):
     db = get_db()
     try:
         return jsonify(db['posts'][post_id - 1])
     except IndexError:
         return 'Not Found', 404
Ejemplo n.º 9
0
 def get(self, user_id):
     db = get_db()
     try:
         return jsonify(db['users'][user_id - 1])
     except IndexError:
         return 'Not found', 404
Ejemplo n.º 10
0
 def get(self, album_id):
     db = get_db()
     try:
         return jsonify(db['albums'][album_id - 1])
     except IndexError:
         return 'Not found', 404