Skip to content

Commit

Permalink
user1 follos user 2
Browse files Browse the repository at this point in the history
  • Loading branch information
vapdev committed Feb 13, 2023
1 parent d82e157 commit 93c1ad5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion apps/twikkerprofile/urls.py
Original file line number Diff line number Diff line change
@@ -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'),
Expand All @@ -13,4 +13,5 @@
path('api/auth_user/', get_auth_user, name='get_user_data'),
path('api/follow/<str:username>', follow_tweeker, name='follow'),
path('api/unfollow/<str:username>', unfollow_tweeker, name='unfollow'),
path('api/user1_follows_user2/<str:username1>/<str:username2>', user1_follows_user2, name='user1_follows_user2'),
]
10 changes: 9 additions & 1 deletion apps/twikkerprofile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
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()})
16 changes: 16 additions & 0 deletions frontend/src/pages/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -73,6 +88,7 @@ async function unfollowUser(){
onMounted(() => {
getUser();
logged_user_follows_user();
})
</script>

0 comments on commit 93c1ad5

Please sign in to comment.