Skip to content

Commit

Permalink
Merge pull request #207 from bounswe/fatih/follow-unfollow
Browse files Browse the repository at this point in the history
profile_view_of_other_users
  • Loading branch information
fatih260 authored May 12, 2024
2 parents 48cafb2 + 094d911 commit aedd3a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/nba_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
path('signup/', views.sign_up, name='signup'),
path('login/', views.log_in, name='login'),
path('feed/', views.feed, name='feed'),
path('profile_view_edit/', views.profile_view_edit, name='profile_view_edit'),
path('user_followings/', views.user_followings, name='user_followings'),
path('user_followers/', views.user_followers, name='user_followers'),
path('follow_user/<int:user_id>', views.follow_user, name='follow_user'),
path('unfollow_user/<int:user_id>', views.unfollow_user, name='unfollow_user'),
path('profile_view_edit/', views.profile_view_edit, name='profile_view_edit'),
path('profile_view_of_other_users/<int:user_id>', views.profile_view_of_other_users, name='profile_view_of_other_users'),
path('reset_password/', views.reset_password, name='reset_password'),
path('post/', views.post, name='post'),
path('search/', views.search, name='search'),
Expand Down
29 changes: 25 additions & 4 deletions backend/nba_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def profile_view_edit(request):
following_count = user.following.count()
followers_count = user.followers.count()
posts = Post.objects.filter(user=user)
#post_contents = [post.content for post in posts]
data = {
'username': user.username,
'email': user.email,
Expand All @@ -169,11 +168,33 @@ def profile_view_edit(request):
'following_count': following_count,
'followers_count': followers_count,
'profile_picture': user.profile_picture.url if user.profile_picture else None,
'posts': [{'content': post.content, 'created_at': post.created_at} for post in posts]
'posts': [{'content': post.content, 'created_at': post.created_at, 'image':post.image} for post in posts]
}
return render(request, 'profile_view_edit.html', data)
#return JsonResponse(data, status=200)
return JsonResponse(data, status=200)
#return render(request, 'profile_view_edit.html', data)

def profile_view_of_other_users(request, user_id):
try:
user = User.objects.get(pk=user_id)
except User.DoesNotExist:
return JsonResponse({'error': 'User not found.'}, status=404)

following_count = user.following.count()
followers_count = user.followers.count()
posts = Post.objects.filter(user=user)

is_following = Follow.objects.filter(follower=request.user, followed=user).exists()

data = {
'username': user.username,
'bio': user.bio,
'profile_picture': user.profile_picture.url if user.profile_picture else None,
'following_count': following_count,
'followers_count': followers_count,
'is_following': is_following,
'posts': [{'content': post.content, 'created_at': post.created_at, 'image':post.image} for post in posts]
}
return JsonResponse(data, status=200)

def reset_password(request):
if request.method != 'POST':
Expand Down

0 comments on commit aedd3a5

Please sign in to comment.