Skip to content

Commit

Permalink
추가: 유저 및 친구 검색 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahayana committed Nov 9, 2023
1 parent f5362ff commit 0c65bea
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions apps/friend/v1/apis/friend_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from rest_framework.response import Response

from apps.account.services.user_service import UserService
from apps.account.v1.serializers.user_serializer import UserLikeKeywordSerilaizer
from apps.account.v1.serializers.user_serializer import (
UserLikeKeywordSerilaizer,
UserReadSerializer,
)
from apps.friend.models import Friend
from apps.friend.services.friend_selector import FriendSelector
from apps.friend.services.friend_service import FriendService
from apps.friend.v1.serializers.friend_serializer import FriendSerializer
from apps.pagination import CommonPagination


class FriendViewSet(viewsets.ModelViewSet):
Expand All @@ -35,7 +37,9 @@ def list(self, request, *args, **kwargs):
"recommend_friend": FriendService.recommend_friend(user=user),
}

return Response(context, template_name="accounts/user_list.html")
return Response(
context, template_name="account/user_list.html", status=status.HTTP_200_OK
)

def destroy(self, request, *args, **kwargs):
"""
Expand All @@ -53,6 +57,19 @@ def destroy(self, request, *args, **kwargs):

return Response(data=data, status=status.HTTP_200_OK)

@action(detail=False, methods=["get"])
def search(self, request, *args, **kwargs):
"""유저 혹은 친구를 검색합니다."""
user = request.user
query = request.query_params.get("q")

friends = FriendSelector.search_friend(user_id=user.id, query=query)
serializer = UserReadSerializer(friends, many=True)

data = {"result": serializer.data}

return Response(data=data, status=status.HTTP_200_OK)

@action(detail=False, methods=["post"])
def keyword(self, request, *args, **kwargs):
"""
Expand Down

0 comments on commit 0c65bea

Please sign in to comment.