diff --git a/Makefile b/Makefile index e09f5bd..c719d03 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ SHELL := /bin/bash include ./.env rundb: + . env/bin/activate docker compose -f docker-compose.dev.yml up -d downdb: diff --git a/app/views/router.py b/app/views/router.py index 48d133b..c4ec4c1 100644 --- a/app/views/router.py +++ b/app/views/router.py @@ -1,5 +1,5 @@ from rest_framework import routers - +from app.views.viewsets.friend_requests import FriendRequestViewSet from app.views.viewsets import UserViewSet, UserProfileViewSet from app.views.viewsets.matching import MatchingViewSet from app.views.viewsets.friend_decision import FriendDecisionViewSet @@ -28,3 +28,8 @@ prefix=r'friend_decisions', viewset=FriendDecisionViewSet, ) + +router.register( + prefix=r'friend_requests', + viewset=FriendRequestViewSet, +) diff --git a/app/views/viewsets/friend_requests.py b/app/views/viewsets/friend_requests.py new file mode 100644 index 0000000..37534db --- /dev/null +++ b/app/views/viewsets/friend_requests.py @@ -0,0 +1,16 @@ +from app.models import FriendDecision +from rest_framework import viewsets, permissions +from app.models.user_profile import UserProfile +from app.serializers.user_profile import UserProfileSerializer + +class FriendRequestViewSet(viewsets.ModelViewSet): + queryset = UserProfile.objects.all() + serializer_class = UserProfileSerializer + permission_classes = ( + permissions.IsAuthenticated, + ) + + def filter_queryset(self, queryset): + received_friend = FriendDecision.objects.filter(receiver_id=self.request.user.id).values_list('sender_id', flat=True) + queryset = queryset.filter(user_id__in=received_friend).exclude(user_id=self.request.user.id) + return queryset