def create_follow(queried_user_identifier): current_user = g.user queried_user_id = g.queried_user_id notification_service.create_notification_for_user(queried_user_id, NotificationType.FOLLOWER, queried_user_id, current_user.user_id) return user_service.create_follow(current_user.user_id, queried_user_id)
def create_reply(post_id): current_user = g.user current_location = g.user_location body = request.form['reply-body'] privacy = request.form['privacy'] new_reply = post_service.create_new_reply(current_user, body, post_id, current_location, privacy) updated_post = post_service.get_post_by_id(current_user.user_id, post_id) notification_service.create_notification_for_user(updated_post.author_id, NotificationType.REPLIED, post_id, current_user.user_id) return { "error" : False, "reply" : new_reply.to_json_dict(), "updated_post" : updated_post.to_json_dict() }
def create_like(post_id): current_user = g.user try: post_service.create_like(post_id, current_user.user_id) except DAOException as e: return { "error" : True } post = post_service.get_post_by_id(current_user.user_id, post_id) # We only get the post for the notification, consider not doing this notification_service.create_notification_for_user(post.author_id, NotificationType.LIKED, post_id, current_user.user_id) return { "error" : False }
def create_friend(queried_user_identifier): current_user = g.user queried_user_id = g.queried_user_id friendship_status = user_service.get_friendship_status(current_user.user_id, queried_user_id) notify_type = None if friendship_status == Friendship.PENDING: notify_type = NotificationType.REQUEST_ACCEPTED elif friendship_status == Friendship.NOTHING: notify_type = NotificationType.REQUEST_PENDING if friendship_status == Friendship.PENDING or friendship_status == Friendship.NOTHING: result = user_service.create_friend(current_user.user_id, queried_user_id) notification_service.create_notification_for_user(queried_user_id, notify_type, queried_user_id, current_user.user_id) return { "error" : result } else: return { "error" : True, "message" : "Request already sent" }