def get_post_replies(post): """ Get all the replies to the passed in post Returns a list of replies """ return reply_dao.get_replies_by_post_id(post.post_id)
def get_post_by_id(current_user_id, post_id): cursor = handled_execute(db_conn, """ SELECT postId, authorId, postBody, postDate, privacy, cityName, longitude, latitude, eventId, eventName, eventLocation, eventStart, eventEnd, imageId, firstName, lastName, nickName, portrait, showLastName, (SELECT COUNT(likes.likerId) FROM likes WHERE likes.postId = posts.postId GROUP BY likes.postId) AS likeCount, (authorId IN (SELECT userId FROM likes WHERE likes.postId = posts.postId)) AS liked, (authorId IN (SELECT firstUserId FROM userFriends WHERE secondUserId = %(current_user_id)s)) AS requestPending, (%(current_user_id)s IN (SELECT firstUserId FROM userFriends WHERE secondUserId = authorId)) AS requestSent, (authorId IN (SELECT firstUserId FROM userFollows WHERE secondUserId = %(current_user_id)s)) AS follower, (%(current_user_id)s IN (SELECT firstUserId FROM userFollows WHERE secondUserId = authorId)) AS following FROM posts LEFT JOIN users ON posts.authorId = users.userId WHERE postId = %(searched_post_id)s AND (privacy != 'friends' OR authorId=%(current_user_id)s OR (authorId IN (SELECT firstUserId FROM userFriends WHERE secondUserId = %(current_user_id)s) AND %(current_user_id)s IN (SELECT firstUserId FROM userFriends WHERE secondUserId = authorId))) ORDER BY postId DESC LIMIT 1;""", { "searched_post_id" : post_id, "current_user_id" : current_user_id }) row = cursor.fetchone() (post_id, author_id, post_body, post_date, privacy, city_name, longitude, latitude, event_id, event_name, event_location, event_start, event_end, image_id, first_name, last_name, nick_name, portrait, show_last_name, likes, liked, request_pending, request_sent, follower, following) = row if likes == None: likes = 0 are_friends = request_sent and request_pending author_name = build_name(first_name, nick_name, last_name, are_friends, show_last_name) post_location = build_location(longitude, latitude, city_name, are_friends, privacy != POST_PRIVACY.HIDE_LOCATION) if(event_id != None): new_post = EventPost(author_id, author_name, portrait, post_body, post_date, privacy, post_location, event_id, event_name, event_location, event_start, event_end) elif(image_id != None): new_post = ImagePost(author_id, author_name, portrait, post_body, post_date, privacy, post_location, image_id) else: new_post = Post(author_id, author_name, portrait, post_body, post_date, privacy, post_location, likes, liked) new_post.post_id = post_id replies = reply_dao.get_replies_by_post_id(post_id, current_user_id) new_post.replies = replies return new_post