Skip to content

Commit

Permalink
Merge pull request #557 from bounswe/BACKEND-554
Browse files Browse the repository at this point in the history
view other profiles
  • Loading branch information
skywllker authored Nov 22, 2024
2 parents 0c5f5a1 + 0288c4d commit f2da378
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/app/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path
from app.views import *
from app.views_directory.profileviews import view_profile, update_profile
from app.views_directory.profileviews import view_profile, update_profile, view_other_profile
from app.views_directory.wordviews import get_word_info, get_turkish_translation, get_similar_level_and_part_of_speech, get_word_details
from app.views_directory.follow_unfollow import follow_user, unfollow_user
from app.views_directory.authentication_endpoints import RegisterView, LoginView, LogoutView, RefreshTokenView
Expand Down Expand Up @@ -42,6 +42,6 @@
path('bookmark/', bookmark_post, name='bookmark_post'),
path('unbookmark/', unbookmark_post, name='unbookmark_post'),
path('get_bookmarked_posts/', get_bookmarked_posts, name='get_bookmarked_posts'),

path('profile/<str:username>/', view_other_profile, name='view_other_profile'),
]

21 changes: 21 additions & 0 deletions backend/app/views_directory/profileviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,24 @@ def update_profile(request):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


@api_view(['GET'])
@permission_classes([IsAuthenticated])
def view_other_profile(request, username):
"""
View a user's profile by their username.
"""
user = get_object_or_404(User, username=username)
profile = get_object_or_404(Profile, user=user)
serializer = ProfileSerializer(profile)
return Response(serializer.data, status=status.HTTP_200_OK)

@api_view(['GET'])
@permission_classes([IsAuthenticated])
def view_other_profile(request, username):
"""
View a user's profile by their username.
"""
user = get_object_or_404(User, username=username)
profile = get_object_or_404(Profile, user=user)
serializer = ProfileSerializer(profile)
return Response(serializer.data, status=status.HTTP_200_OK)

0 comments on commit f2da378

Please sign in to comment.