-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(matching): Add mathing friends list API
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |