Ejemplo n.º 1
0
    def on_post(self, req, resp, tid):
        if req.content_length in (None, 0):
            return

        body = req.stream.read()

        if not body:
            raise falcon.HTTP_BAD_REQUEST()

        try:
            doc = json.loads(body.decode('utf-8'))
        except (ValueError, UnicodeDecodeError):
            raise falcon.HTTP_BAD_REQUEST()

        thread_dao = threadDAO.ThreadDAO()
        resp_body, resp_status = thread_dao.vote_thread(tid, doc)
        resp.body = json.dumps(resp_body)
        resp.status = resp_status
Ejemplo n.º 2
0
 def get_details(self, post_id, related=[]):
     post = self.db.query("SELECT * FROM posts WHERE id={}".format(post_id))
     if len(post) == 0:
         return {"message": "Post not found"}, falcon.HTTP_404
     post = {"post": self.post_from_table(post[0])}
     if related:
         related = related.split(",")
         for i in related:
             if i == "user":
                 user_dao = userDAO.UserDAO()
                 post["author"] = user_dao.get_user(
                     post["post"]["author"])[0]
             if i == "forum":
                 forum_dao = forumDAO.ForumDAO()
                 post["forum"] = forum_dao.forum_info(post["post"]["forum"])
             if i == "thread":
                 import tech_db_forum.dao.threadDAO as threadDAO
                 thread_dao = threadDAO.ThreadDAO()
                 post["thread"] = thread_dao.get_details(
                     post["post"]["thread"])[0]
     return post, falcon.HTTP_200
Ejemplo n.º 3
0
 def on_get(self, req, resp, tid):
     thread_dao = threadDAO.ThreadDAO()
     resp_body, resp_status = thread_dao.get_posts(tid, req.get_param("limit"), req.get_param("since"),
                                                   req.get_param("sort"),  req.get_param("desc"))
     resp.body = json.dumps(resp_body)
     resp.status = resp_status
Ejemplo n.º 4
0
 def on_get(self, req, resp, tid):
     thread_dao = threadDAO.ThreadDAO()
     resp_body, resp_status = thread_dao.get_details(tid)
     resp.body = json.dumps(resp_body)
     resp.status = resp_status