예제 #1
0
def route_list_users_real_time(user_id: str):
    """Endpoint for getting users."""
    user = User.objects.get_or_404(id=user_id)
    user.identify(request)

    user_ids = user.list_realtime_user_ids()
    users = User.list(id__in=user_ids).as_pymongo()
    response = encode(list(users))
    return Response(response, mimetype="application/json")
예제 #2
0
def route_list_users_close(user_id: str, distance: int):
    """Endpoint for getting users."""
    user = User.objects.get_or_404(id=user_id)
    user.identify(request)

    distance = distance or 5

    if not user.location or not user.location["coordinates"]:
        return Response(json.dumps([]), mimetype="application/json")

    close_user_ids = user.list_user_ids_within_distance(distance=distance)
    users = User.list(id__in=close_user_ids).as_pymongo()
    response = encode(list(users))
    return Response(response, mimetype="application/json")
예제 #3
0
def route_list_users_recommendation(user_id: str):
    """Endpoint for getting recommended users."""
    user = User.objects.get_or_404(id=user_id)
    user.identify(request)

    recommendation = user.get_recommendation()

    last_recommended_at = pendulum.from_timestamp(
        recommendation.last_recommended_at, tz="Asia/Seoul")
    is_today_recommended = last_recommended_at.date() == pendulum.today().date()

    if is_today_recommended and len(recommendation.user_ids) >= 2:
        user_ids = recommendation.user_ids
    else:
        user_ids = user.list_recommended_user_ids()
        user_ids.extend(recommendation.user_ids)
        recommendation.user_ids = user_ids
        recommendation.last_recommended_at = pendulum.now().int_timestamp
        recommendation.save()

    users = User.list(id__in=user_ids[:MAXIMUM_RECOMMENDATION_SHOW_COUNT]).as_pymongo()
    users = sort_order_by_ids(user_ids, users)
    response = encode(list(users))
    return Response(response, mimetype="application/json")