diff --git a/backend/app/urls.py b/backend/app/urls.py index 631bef6e..3f439193 100644 --- a/backend/app/urls.py +++ b/backend/app/urls.py @@ -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 @@ -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//', view_other_profile, name='view_other_profile'), ] diff --git a/backend/app/views_directory/profileviews.py b/backend/app/views_directory/profileviews.py index f6855ee5..24c731c0 100644 --- a/backend/app/views_directory/profileviews.py +++ b/backend/app/views_directory/profileviews.py @@ -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)