Skip to content

Commit

Permalink
feature(matching): Add mathing friends list API
Browse files Browse the repository at this point in the history
  • Loading branch information
kjy2844 committed May 8, 2022
1 parent e393e1b commit 61e5f66
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/views/router.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
from rest_framework import routers

from app.views.viewsets import UserViewSet, UserProfileViewSet
from app.views.viewsets.matching import MatchingViewSet

router = routers.DefaultRouter()

router.register(
prefix=r'users',
viewset=UserViewSet,
basename='users',
)

router.register(
prefix=r'user_profiles',
viewset=UserProfileViewSet,
basename='user_profiles',
)

router.register(
prefix=r'matching',
viewset=MatchingViewSet,
basename='matching',
)
25 changes: 25 additions & 0 deletions app/views/viewsets/matching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.core.paginator import Paginator

from app.models import FriendDecision
from rest_framework import viewsets, permissions, mixins

from app.models.user_profile import UserProfile
from app.serializers.user_profile import UserProfileSerializer


class MatchingViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
# user proflie의 사용자 중 decisions table을 조회해서 내가 sender도 receiver도 아닌 사용자들 찾아옴
# user id가 FriendDecision의 sender와 receiver에 없는 경우
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)
sent_friend = FriendDecision.objects.filter(sender_id=self.request.user.id).values_list('receiver_id', flat=True)

excludes = [self.request.user.id, *received_friend, *sent_friend]
queryset = queryset.exclude(user_id__in=excludes)
return queryset

0 comments on commit 61e5f66

Please sign in to comment.