Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search and feed are mostly done #218

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions backend/nba_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def profile_view_edit(request, user_id):
return JsonResponse({'message': 'Account information updated successfully.'}, status=200)

if request.method == 'GET':
# user = User.objects.get(user_id=user_id)
user = User.objects.get(username=user_id)
following_count = user.following.count()
followers_count = user.followers.count()
Expand Down Expand Up @@ -222,8 +221,6 @@ def reset_password(request):
return JsonResponse({'message': 'Password reset successful.'}, status = 200)




def follow_user(request, user_id):
if request.method != 'POST':
return JsonResponse({'error': 'Only POST requests are allowed.'}, status=405)
Expand All @@ -249,8 +246,6 @@ def follow_user(request, user_id):
return JsonResponse({'message': 'You have successfully followed the user.'}, status=200)




def unfollow_user(request, user_id):
if request.method != 'POST':
return JsonResponse({'error': 'Only POST requests are allowed.'}, status=405)
Expand All @@ -275,6 +270,10 @@ def unfollow_user(request, user_id):

@login_required
def feed(request):
followed_users = request.user.following.all()
followed_posts = Post.objects.filter(user__in=followed_users)
post_ids = followed_posts.values_list('post_id', flat=True)
return JsonResponse({'post_ids': list(post_ids)}, status=200)
# Only authenticated users can access this view
return render(request, 'feed.html')

Expand All @@ -284,9 +283,13 @@ def search(request):
try:
team = search_team(query)
player = search_player(query)
return JsonResponse({'team': team, 'player': player})
print("team:", team, "player:", player)
posts = Post.objects.filter(content__icontains=query)
return JsonResponse({'team': team, 'player': player, 'posts': [{'id': post.post_id, 'content': post.content, 'created_at': post.created_at} for post in posts]})
except:
return JsonResponse({"error:": "error, please try again"})


#return render(request, 'search.html')

def search_player(query):
Expand All @@ -303,7 +306,6 @@ def search_player(query):

response = requests.get(endpoint_url, params={'format': 'json', 'query': sparql_query})
data = response.json()
print('player:', data)
if response.status_code == 500:
return {"response:": "error, please try a different query"}
elif data['results']['bindings'] == []:
Expand Down Expand Up @@ -350,7 +352,6 @@ def search_team(query):

query_team = ''
for team in teams:
print('query_team:', query_team)
if query_team != '':
break
for word in team:
Expand Down