Skip to content

Commit

Permalink
feat(requests): Add requests list API
Browse files Browse the repository at this point in the history
  • Loading branch information
TriangleYJ committed May 13, 2022
1 parent c8c4eab commit d078e53
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SHELL := /bin/bash
include ./.env

rundb:
. env/bin/activate
docker compose -f docker-compose.dev.yml up -d

downdb:
Expand Down
7 changes: 6 additions & 1 deletion app/views/router.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,3 +28,8 @@
prefix=r'friend_decisions',
viewset=FriendDecisionViewSet,
)

router.register(
prefix=r'friend_requests',
viewset=FriendRequestViewSet,
)
16 changes: 16 additions & 0 deletions app/views/viewsets/friend_requests.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d078e53

Please sign in to comment.