Example #1
0
def get_friendlist(request):
    status = status_response()
    # Get friend list
    if request.method == 'GET':
        data = serviceAPI.relationService.list_all_friends(
            current_user.get_user_id(request))
        if data['status']:
            status.attach_data('data', data, isSuccess=True)

    # Follow a friend
    elif request.method == 'POST':
        follow_ID = request.POST.get('follow_ID')
        response = serviceAPI.relationService.add_follow(follow_ID)
        if response['status']:
            status.attach_data('data', data, isSuccess=True)

    # Delete a friend
    elif request.method == 'DELETE':
        email = QueryDict(request.body).get('email')
        follow_ID = QueryDict(request.body).get('follow_ID')
        response = serviceAPI.relationService.delete_follow(follow_ID)
        if response['status']:
            status.attach_data('data', data, isSuccess=True)

    return JsonResponse(status.data)
Example #2
0
def create_a_new_place_post(request):
    # Create an attraction
    if request.method == 'POST':
        # Read Data
        name = request.form.get('name')
        lat = request.form.get('lat')
        lng = request.form.get('lng')
        intro = request.form.get('intro')
        rating = request.form.get('rating')
        cover_file = request.files.get('cover')
        marker_file = request.files.get('marker')

        # Calculate the score based on the user experience and the rating
        score = (float(rating) + 10)

        user_id = current_user.get_user_id(request)
        
        attraction_service.post_attraction(
            name, lat, lng, intro, rating, cover_file, marker_file,
            user_id
        )

        return JsonResponse({'status': 'success'}), 201

    else:
        return '', 404
Example #3
0
def get_profile(request):
    if request.method == 'GET':
        # Read data
        email = request.form.get('email')
        data = login_service.get_profile(current_user.get_user_id(request))
        return JsonResponse({'ID':data['exp_id'], 'experience': data['experience'], 'name': data['name'], 'email': data['email']})
    else:
        return "", 400
Example #4
0
def get_map(request):
    status = status_response()
    if request.method == 'GET':
        data = serviceAPI.mapService.load_map(
            current_user.get_user_id(request))
        if data['status']:
            status.attach_data('data', data, isSuccess=True)
    return JsonResponse(status.data)
Example #5
0
def get_map(request):
    if request.method == 'GET':
        
        rule = request.form.get('rule')
        if not rule: rule = 'default' # Set default rule
        data = Map_App.get_map_attractions(current_user.get_user_id(request), rule)
        return JsonResponse(data)
    else:
        return "", 400
Example #6
0
def request_place_look_up(request):
    status = status_response()
    if request.method == 'GET':
        attraction_ID = request.GET.get('attraction_ID')
        user_ID = current_user.get_user_id(request)
        data = serviceAPI.mapService.get_attraction_moment(
            user_ID, attraction_ID)
        if data['status']:
            status.attach_data('data', data, isSuccess=True)
    return JsonResponse(status.data)
Example #7
0
def get_my_profile(request):
    status = status_response()
    if request.method == 'GET':
        # Read data
        user_ID = current_user.get_user_id(request)
        data = serviceAPI.authService.user_get_profile(user_ID=user_ID)

        if data['status']:
            status.attach_data('data', data, isSuccess=True)
    return JsonResponse(status.data)
Example #8
0
def get_friendlist(request):

    # Get friend list
    if request.method == 'GET':
       
        friendlist = relation_service.show_all_friends(current_user.get_user_id(request))
        return JsonResponse(friendlist)

    # Follow a friend
    elif request.method == 'POST':
        to_email = request.form.get('email')
        status = 1

        relation_service.add_follow(current_user.get_user_id(request), to_email, status)

        return JsonResponse({'status': 'success'}), 201

    # Delete a friend
    elif request.method == 'DELETE':
        email = request.args.get('email')
        relation_service.delete_follow(current_user.get_user_id(request), email)
        return JsonResponse({'status': 'success'}), 201
    else:
        return "", 400
Example #9
0
def new_moment(request):
    status = status_response()
    # Create an attraction
    if request.method == 'POST':
        # Read Data
        name = request.POST.get('name')
        lat = request.POST.get('lat')
        lng = request.POST.get('lng')
        intro = request.POST.get('intro')
        rating = request.POST.get('rating')

        # Calculate the score based on the user experience and the rating
        score = (float(rating) + 10)

        user_ID = current_user.get_user_id(request)

        response = serviceAPI.attractionService.postMoment(
            name, lat, lng, intro, rating, user_ID)
        if response['status']:
            status.set_status(True)
    return JsonResponse(status.data)