Example #1
0
def get_user_posts(queried_user_identifier):
	current_user = g.user
	current_location = g.user_location
	requested_user = g.queried_user

	max_dist_str = request.args.get('max_dist', 25)
	max_id_str = request.args.get('max_id', None)
	page_num_str = request.args.get('page', 1)
	post_per_page_str = request.args.get('post_per_page', 10)

	try:
		max_dist = int(max_dist_str)
		page_num = int(page_num_str)
		post_per_page = int(post_per_page_str)

		max_id = None
		if(max_id_str != None):
			max_id = int(max_id_str)
	except ValueError as e:
		return {
			"error" : True
		}

	friendship_status = user_service.get_friendship_status(current_user.user_id, requested_user.user_id)
	are_friends = friendship_status == Friendship.FRIENDS

	current_posts = post_service.get_posts_by_user(current_user.user_id, requested_user, are_friends, page_num, post_per_page, max_id)

	if max_id == None and len(current_posts) > 0:
		max_id = current_posts[0].post_id

	output_json = {
		"error" : False,
		"max_id" : max_id,
		"current_location" : current_location.to_json_dict(),
		"pagination": {
			"page_num" : page_num,
			"post_per_page" : post_per_page,
			"length" : len(current_posts)
		}
	}

	posts_json = []
	for post in current_posts:
		post_json = post.to_json_dict()

		posts_json.append(post_json)

	output_json["posts"] = posts_json

	return output_json
Example #2
0
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" }
Example #3
0
def get_user_profile(queried_user_identifier):
	requested_user = g.queried_user
	requested_user_id = g.queried_user_id
	current_user = g.user
	current_location = g.user_location

	friendship_status = user_service.get_friendship_status(current_user.user_id, requested_user_id)
	are_friends = friendship_status == Friendship.FRIENDS

	posts = post_service.get_posts_by_user(current_user.user_id, requested_user, are_friends)
	friend_objs = user_service.get_friends(requested_user_id)
	followers = user_service.get_followers(requested_user_id, True)

	friend_json_dicts = []
	for friend in friend_objs:
		friend_json_dicts.append(friend.to_json_dict())

	post_json_dicts = []
	for post in posts:
		post_json_dict = post.to_json_dict()
		post_json_dicts.append(post_json_dict)

	# Build the result
	result_json_dict = requested_user.to_json_dict()
	result_json_dict['friends'] = friend_json_dicts
	result_json_dict['posts'] = post_json_dicts
	result_json_dict['follower_count'] = len(followers)
	result_json_dict['current_user_info'] = {
		"location" : current_location.to_json_dict(),
		"following" : current_user.user_id in followers,
		"friendship_status" : friendship_status
	}
	if current_user.user_id == requested_user_id:
		result_json_dict["self"] = current_user.user_id == requested_user_id

	return result_json_dict