def get(self, topic_id): #done try: links = DaoImpl.getLinks(topic_id) linksDict = [Util.linkToDict(link) for link in links] self.set_status(200) self.write(simplejson.dumps(linksDict)) except TopicNotFoundException, e: self.set_status(404) self.write(error(e.__str__())) #figure how to write exception text.
def put(self, link_id): #vote up/down information will be stored in the TopicLink table. if self.request.body: linkDict = simplejson.loads(self.request.body) try: link = DaoImpl.updateLink(link_id, linkDict, None) self.set_status(200) self.write(simplejson.dumps(Util.linkToDict(link))) except Exception, e: self.set_status(400) self.write(error(e.__str__()))
def get(self, topic_id, link_id): link = DaoImpl.getLink(link_id) if link: linkDict = Util.linkToDict(link) self.set_status(200) self.write(simplejson.dumps(linkDict)) else: self.set_status(404) self.write(error('Link not found.')) self.set_header("Content-Type", "application/json")
def post(self, topic_id):#done if self.request.body: linkDict = simplejson.loads(self.request.body) try: topic = DaoImpl.getTopic(topic_id) if not topic: raise TopicNotFoundException link = DaoImpl.createLinkFromDict(linkDict, topic) DaoImpl.addLinkToTopic(topic, link) self.set_status(200) self.write(simplejson.dumps(Util.linkToDict(link))) except Exception, e: self.set_status(400) self.write(error(e.__str__()))