class LikeChatMessage(Resource): def __init__(self): self.handler = MessageHandler() def get(self, mid): likers = self.handler.get_likers(mid) return jsonify(likers=likers, likes=len(likers)) @jwt_required def post(self, mid): message = self.handler.like_message(mid) return jsonify(message=message)
class Messages(Resource): def __init__(self): self.handler = MessageHandler() def get(self): messages = self.handler.get_all_messages() return jsonify(messages=messages)
class Message(Resource): def __init__(self): self.handler = MessageHandler() def get(self, mid): message = self.handler.get_message(mid) return jsonify(message=message)
def num_of_replies_photo(pid): """ Gets number of photo replies per day for the given photo id :param pid: int :return: JSON """ return MessageHandler().get_num_replies_photo(pid)
def num_of_dislikes_photos(pid): """ Gets number of dislikes for the given photo id :param pid: int :return: JSON """ return MessageHandler().get_num_dislikes_photo(pid)
class DislikeChatMessage(Resource): def __init__(self): self.handler = MessageHandler() def get(self, mid): dislikers = MessageHandler().get_dislikers(mid) return jsonify(dislikers=dislikers, dislikes=len(dislikers)) @jwt_required def post(self, mid): message = self.handler.dislike_message(mid) return jsonify(message=message)
class ReplyChatMessage(Resource): def __init__(self): self.handler = MessageHandler() def get(self, mid): replies = self.handler.get_replies(mid) return jsonify(replies=replies) @jwt_required def post(self, mid): parser = reqparse.RequestParser() parser.add_argument('message', help=HELP_TEXT, required=True) parser.add_argument('cid', help=HELP_TEXT, required=True) data = parser.parse_args() data['img'] = None if 'img' in request.files and request.files['img']: data['img'] = request.files['img'] response, status = ChatHandler().reply_chat_message(data, mid) return app.response_class(response=response, status=status, mimetype='application/json')
def getReplyString(repID): return MessageHandler().getReplyForDisplay(repID)
def getMessageThatReplied(mid): return MessageHandler().getMessageThatReplied(mid)
def trending_topics(): """ Gets trending hashtags from database :return: JSON """ return MessageHandler().get_trending_hashtags(), 200
def messagesByUserId(uid): return MessageHandler().searchMessagesByUserId(uid)
def messagesByChatName(): if request.method == 'GET': return MessageHandler().getAllMessages()
def messagesOfUserFromGroup(uid, gid): if request.method == 'GET': return MessageHandler().searchMessagesOfUserFromGroup(uid, gid) elif request.method == 'POST': return MessageHandler().postMessage(uid, gid, request.get_json())
def messagesFromGroupId(gid): return MessageHandler().searchMessagesByGroupId(gid)
def num_of_dislikes(): """ Gets number of dislikes per day from database :return: JSON """ return MessageHandler().get_num_dislikes_daily(), 200
def num_of_posts(): """ Gets number of messages posted per day from database :return: JSON """ return MessageHandler().get_num_messages_daily(), 200
def get(self, mid): dislikers = MessageHandler().get_dislikers(mid) return jsonify(dislikers=dislikers, dislikes=len(dislikers))
def repliesOfMessage(mid): return MessageHandler().getRepliesForMessage(mid)
def __init__(self): self.handler = MessageHandler()
def getMessageBymsgId(mid): return MessageHandler().getMessageByMsgId(mid)