From 93c1ad540695d52bfda4eccebe8feb88989da25b Mon Sep 17 00:00:00 2001 From: vitor Date: Sun, 12 Feb 2023 21:01:58 -0300 Subject: [PATCH] user1 follos user 2 --- apps/twikkerprofile/urls.py | 3 ++- apps/twikkerprofile/views.py | 10 +++++++++- frontend/src/pages/Profile.vue | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/twikkerprofile/urls.py b/apps/twikkerprofile/urls.py index afada87..c511e38 100644 --- a/apps/twikkerprofile/urls.py +++ b/apps/twikkerprofile/urls.py @@ -1,6 +1,6 @@ from django.urls import path from apps.twikkerprofile.views import edit_profile, unfollow_tweeker, followers, follows, \ - follow_tweeker, toggle_dark_mode, get_user_data, get_auth_user + follow_tweeker, toggle_dark_mode, get_user_data, get_auth_user, user1_follows_user2 urlpatterns = [ path('editprofile/', edit_profile, name='edit_profile'), @@ -13,4 +13,5 @@ path('api/auth_user/', get_auth_user, name='get_user_data'), path('api/follow/', follow_tweeker, name='follow'), path('api/unfollow/', unfollow_tweeker, name='unfollow'), + path('api/user1_follows_user2//', user1_follows_user2, name='user1_follows_user2'), ] \ No newline at end of file diff --git a/apps/twikkerprofile/views.py b/apps/twikkerprofile/views.py index 9ba42e5..9295023 100644 --- a/apps/twikkerprofile/views.py +++ b/apps/twikkerprofile/views.py @@ -116,4 +116,12 @@ def follow_tweeker(request, username): user = get_object_or_404(User, username=username) request.user.twikkerprofile.follows.add(user.twikkerprofile) - return JsonResponse({'success': True}) \ No newline at end of file + return JsonResponse({'success': True}) + + +@permission_classes((IsAuthenticated, )) +@api_view(['GET']) +def user1_follows_user2(request, username1, username2): + user1 = get_object_or_404(User, username=username1) + user2 = get_object_or_404(User, username=username2) + return JsonResponse({'follows': user1.twikkerprofile.follows.filter(user=user2).exists()}) \ No newline at end of file diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index 8f73c93..67c60e2 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -42,6 +42,21 @@ const user = ref(''); const followed_by = ref(''); const following = ref(''); +async function logged_user_follows_user(){ + await axios.get(`/api/user1_follows_user2/${store.state.username}/${route.params.username}`,) + .then(response => { + if(response.data['follows'] == true){ + console.log("USER FOLLOWS PROFILE USER") + followed_by.value = true + }else{ + console.log("USER DOES NOT FOLLOW PROFILE USER") + followed_by.value = false + } + }) + .catch(error => { + console.log('error' + error) + }) +} async function getUser(){ await axios.get(`/api/user_data/${route.params.username}`,) .then(response => { @@ -73,6 +88,7 @@ async function unfollowUser(){ onMounted(() => { getUser(); + logged_user_follows_user(); }) \ No newline at end of file