Esempio n. 1
0
    def on_get(self, req, resp, slug):
        forum_dao = forumDAO.ForumDAO()
        resp_body, resp_status = forum_dao.get_forum_threads(slug, req.get_param("limit"), req.get_param("since"),
                                                             req.get_param("desc"))
        resp.body = json.dumps(resp_body)

        resp.status = resp_status
Esempio n. 2
0
    def on_post(self, req, resp):
        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()
        forum_dao = forumDAO.ForumDAO()
        resp_body, resp_status = forum_dao.create_forum(doc)
        resp.body = json.dumps(resp_body)
        resp.status = resp_status
Esempio n. 3
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
Esempio n. 4
0
 def on_get(self, req, resp, slug):
     forum_dao = forumDAO.ForumDAO()
     resp_body, resp_status = forum_dao.get_forum_details(slug)
     resp.body = json.dumps(resp_body)
     resp.status = resp_status