Beispiel #1
0
 def get(self):
     args = self.parser.parse_args(strict=True)
     posts_list = repo.read_all_by_criteria(args["criteria"], args["value"])
     response = app.make_response("")
     response.status_code = 200
     response.data = jsonpickle.encode(posts_list)
     return response
Beispiel #2
0
 def get(self, post_id):
     abort_if_post_doesnt_exist(post_id)
     post = repo.get(post_id)
     response = app.make_response("")
     response.status_code = 200
     response.data = jsonpickle.encode(post)
     return response
Beispiel #3
0
    def post(self):
        payload = jsonpickle.decode(flask.request.data)
        if (not check_if_current_user_is_guest()
                and check_current_user_id(payload["user_id"])):

            post_id = repo.create(payload["user_id"], payload["title"],
                                  payload["text"])
            post = repo.get(post_id)
            response = app.make_response("")
            response.status_code = 201
            response.data = jsonpickle.encode(post)
            return response
        abort(403, message="You have not enough privileges to create post")
Beispiel #4
0
    def delete(self, post_id):
        abort_if_post_doesnt_exist(post_id)
        post = repo.get(post_id)
        if (check_current_user_id(post.user_id)
                or check_if_current_user_is_privileged()):

            repo.delete(post_id)
            response = app.make_response("Post %d deleted successfully" %
                                         post_id)
            response.status_code = 204
            return response
        abort(403,
              message="You have not enough privileges to delete selected post")
Beispiel #5
0
 def patch(self, post_id):
     abort_if_post_doesnt_exist(post_id)
     payload = jsonpickle.decode(flask.request.data)
     user_id = repo.get(post_id).user_id
     if ((check_current_user_id(payload["user_id"])
          and check_current_user_id(user_id))
             or check_if_current_user_is_privileged()):
         repo.update(post_id, payload["user_id"], payload["title"],
                     payload["text"])
         post = repo.get(post_id)
         response = app.make_response("")
         response.status_code = 201
         response.data = jsonpickle.encode(post)
         return response
     abort(403,
           message="You have not enough privileges to delete selected post")