Exemple #1
0
 def getNumberOfPostsPerDayByUser(self, uID):
     dao = PostDAO()
     result = dao.getNumberOfPostsPerDayByUser(uID)
     if not result:
         return jsonify(Error="Not found"), 404
     mapped_result = mapInteractionPerDayToDict(result)
     return jsonify(mapped_result)
Exemple #2
0
 def getNumberOfRepliesForGivenPost(self, pID):
     dao = PostDAO()
     result = dao.getNumberOfRepliesForGivenPost(pID)
     if not result:
         return jsonify(Error="Not found"), 404
     mapped_result = mapReplyCountToDict(result)
     return jsonify(mapped_result)
Exemple #3
0
 def getRepliesByPostIDDETAILED(self, pID):
     dao = PostDAO()
     result = dao.getRepliesByPostID(pID)
     mapped_result = []
     for r in result:
         mapped_result.append(mapReplyToDict(r))
     return mapped_result
Exemple #4
0
 def getNumberOfDislikesForGivenPost(self, pID):
     dao = PostDAO()
     result = dao.getNumberOfReactionsForGivenPost(pID, "dislike")
     if not result:
         return jsonify(Error="Not found"), 404
     mapped_result = mapReacCountToDict(result)
     return jsonify(mapped_result)
Exemple #5
0
 def getNumberOfRepliesPerDay(self):
     dao = PostDAO()
     result = dao.getNumberOfRepliesPerDay()
     if not result:
         return jsonify(Error="Not found"), 404
     mapped_result = []
     for r in result:
         mapped_result.append(mapInteractionPerDayToDict(r))
     return jsonify(mapped_result)
Exemple #6
0
 def getRepliesByPostID(self, pID):
     dao = PostDAO()
     result = dao.getRepliesByPostID(pID)
     if not result:
         return jsonify(Error="Not found"), 404
     mapped_result = []
     for r in result:
         mapped_result.append(mapReplyToDict(r))
     return jsonify(mapped_result)
Exemple #7
0
 def getPostByGroupIdDETAILED(self, gID):
     dao = PostDAO()
     result = dao.getPostsByGroupID(gID)
     mapped_result = []
     for r in result:
         mapped_result.append(
             mapPostToDictDETAILED(r,
                                   self.getRepliesByPostIDDETAILED(r[0])))
     return jsonify(mapped_result)
Exemple #8
0
 def getAllPost(self):
     dao = PostDAO()
     result = dao.getAllPosts()
     if not result:
         return jsonify(Error="Not found"), 404
     mapped_result = []
     for r in result:
         mapped_result.append(mapPostToDict(r))
     return jsonify(mapped_result)
Exemple #9
0
 def getListOfUsersWhoDislikedPost(self, pID):
     dao = PostDAO()
     result = dao.getListOfUsersWhoReactedPost(pID, "dislike")
     if not result:
         return jsonify(Error="Not found")
     mapped_result = []
     for r in result:
         mapped_result.append(mapToReactDict(r))
     return jsonify(mapped_result)
Exemple #10
0
 def getPostByGroupId(self, gID):
     dao = PostDAO()
     result = dao.getPostsByGroupID(gID)
     if not result:
         return jsonify(Error="Not found"), 404
     mapped_result = []
     for r in result:
         mapped_result.append(mapPostToDict(r))
     return jsonify(mapped_result)
Exemple #11
0
 def reactToPost(self, post_id, json, reaction):
     if json is None:
         return jsonify(Error="Malformed post request"), 400
     else:
         user_id = json['user_id']
         dao = PostDAO()
         result = dao.reactToPost(user_id, post_id, reaction)
         if not result:
             return jsonify(Error="Already reacted to this post"), 777
         return jsonify(result)
Exemple #12
0
    def replyToPostID(self, post_id, json):
        if json is None:
            return jsonify(Error="Malformed post request"), 400
        else:
            reply_message = json['reply_message']
            user_id = json['user_id']

            dao = PostDAO()
            result = dao.replyToPostID(reply_message, post_id, user_id)
            return jsonify(result)
Exemple #13
0
    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
Exemple #14
0
    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
Exemple #15
0
 def getNumberOfPostPerDayByUser(self, uID):
     dao = PostDAO()
     result = "5"
     return jsonify(result)
Exemple #16
0
 def getLikesByPostId(self, pID):
     dao = PostDAO()
     result = dao.getLikesByPostId(pID)
     return jsonify(Likes=result)
Exemple #17
0
 def getNumberOfPostPerDay(self):
     dao = PostDAO()
     result = dao.getNumberOfPostPerDay()
     return jsonify(Posts=result)
Exemple #18
0
 def getAllPost(self):
     dao = PostDAO()
     result = dao.getAllPost()
     return jsonify(Posts=result)
Exemple #19
0
 def getMessageByPostID(self, pID):
     dao = PostDAO()
     result = dao.getMessageByPostID(pID)
     return jsonify(Message=result)
Exemple #20
0
 def getNumberOfRepliesPerDay(self):
     dao = PostDAO()
     result = dao.getNumberOfRepliesPerDay()
     return jsonify(Replies=result)
Exemple #21
0
 def getMediaByPostID(self, pID):
     dao = PostDAO()
     result = dao.getMediaByPostID(pID)
     return jsonify(Contacts=result)
Exemple #22
0
 def getPostByGroupId(self, gID):
     dao = PostDAO()
     result = dao.getPostByGroupId(gID)
     return jsonify(Post=result)
Exemple #23
0
 def getNumberOfDislikesPerDay(self):
     dao = PostDAO()
     result = dao.getNumberOfDislikesPerDay()
     return jsonify(Dislikes=result)
Exemple #24
0
 def getNumberOfRepliesForGivenPost(self, pID):
     dao = PostDAO()
     result = dao.getNumberOfRepliesForGivenPost(pID)
     return jsonify(Replies=result)
Exemple #25
0
 def getAuthorByPostID(self, pID):
     dao = PostDAO()
     result = dao.getAuthorByPostID(pID)
     return jsonify(Author=result)
Exemple #26
0
 def getPostsByUserID(self, uID):
     dao = PostDAO()
     result = dao.getPostsByUserID(uID)
     return jsonify(Post=result)
Exemple #27
0
 def getPostsPerDayByUser(self, uID):
     dao = PostDAO()
     result = dao.getPostsPerDayByUser(uID)
     return jsonify(Posts=result)
Exemple #28
0
 def getPostByID(self, pID):
     dao = PostDAO()
     result = dao.getPostByID(pID)
     return jsonify(Post=result)