def createNewHashtag(self, form): """Create a new Hashtag""" if len(form) != 2: return jsonify(Error="Malformed post request"), 400 else: tag = form['tag'] if tag: dao = ReactionDAO() hid = dao.createHashtag(tag) result = self.map_hashtag_attributes(hid, tag) return jsonify(Hashtag=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def insertMessage(self, content, pid, gid): cursor = self.conn.cursor() query = "INSERT INTO messages (content, pid, gid) VALUES (%s, %s, %s)" \ "RETURNING mid, date;" cursor.execute(query, (content, pid, gid)) mid_date = cursor.fetchone() self.conn.commit() reaction_dao = ReactionDAO() hashtags = set(tag[1:] for tag in content.split() if tag.startswith("#")) for tag in hashtags: hid = reaction_dao.getTagId(tag) if not hid: hid = reaction_dao.createHashtag(tag) reaction_dao.insertTag(mid_date[0], hid) else: reaction_dao.insertTag(mid_date[0], hid) return mid_date