From f5362ffc3393328096e7282fd8907cbe49f7c4e7 Mon Sep 17 00:00:00 2001 From: sahayana Date: Thu, 9 Nov 2023 15:12:47 +0400 Subject: [PATCH] =?UTF-8?q?=EC=B6=94=EA=B0=80:=20=ED=98=84=EC=9E=AC=20?= =?UTF-8?q?=EC=B9=9C=EA=B5=AC=20=EB=AA=A9=EB=A1=9D=20=EB=B0=8F=20=EC=B6=94?= =?UTF-8?q?=EC=B2=9C=EC=B9=9C=EA=B5=AC=20=EB=A0=8C=EB=8D=94=EB=A7=81=20api?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/friend/v1/apis/friend_api.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/friend/v1/apis/friend_api.py b/apps/friend/v1/apis/friend_api.py index 5015220..0c0f41a 100644 --- a/apps/friend/v1/apis/friend_api.py +++ b/apps/friend/v1/apis/friend_api.py @@ -1,12 +1,13 @@ import json -from rest_framework import permissions, status, viewsets +from rest_framework import permissions, renderers, status, viewsets from rest_framework.decorators import action 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.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 @@ -18,6 +19,24 @@ class FriendViewSet(viewsets.ModelViewSet): permission_classes = [permissions.IsAuthenticated] serializer_class = FriendSerializer + def get_renderers(self): + if self.action == "list": + renderer_classes = [renderers.TemplateHTMLRenderer] + else: + renderer_classes = [renderers.JSONRenderer] + return [renderer() for renderer in renderer_classes] + + def list(self, request, *args, **kwargs): + """현재 친구 목록과 추천 친구를 렌더링합니다.""" + user = request.user + context = { + "user": user, + "friends": FriendSelector.get_friends_list(user_id=user.id), + "recommend_friend": FriendService.recommend_friend(user=user), + } + + return Response(context, template_name="accounts/user_list.html") + def destroy(self, request, *args, **kwargs): """ 친구 상태를 해제합니다.