def addPost(self, gID, json): dao = PostDAO() if len(json) != 2: return jsonify(Error="Malformed post request"), 400 else: groupID = json['groupID'] author = json['author'] message = json['message'] media = json['media'] if groupID and author and message and media: gID = dao.addPost(groupID, author, message, media) return jsonify(gID), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def addPost(self, gID, request): dao = PostDAO() chat_group_id = gID user_id = request.values['user_id'] message = request.values['message'] file = request.files['file'] if chat_group_id and user_id and message and file: if file.filename == '': return jsonify( Error="Unexpected attributes in post request"), 400 if allowed_file(file.filename): post_id = dao.addPost(message, chat_group_id, user_id) filename = "img_" + str(post_id) + "_" + secure_filename( file.filename) file.save(os.path.join(UPLOAD_FOLDER, filename)) dao.addPostMedia(post_id, filename) hashtags = { tag.strip("#") for tag in message.split() if tag.startswith("#") } noDupHashtags = [] for tag in hashtags: if tag.lower() not in noDupHashtags: noDupHashtags.append(tag.lower()) dao.insertHashtag(tag.lower(), post_id) return jsonify(post_id), 201 else: return jsonify(Error="NO filename"), 400 else: return jsonify(Error="Unexpected attributes in post request"), 400