Skip to content

Commit

Permalink
feat: 친구 정보만 응답
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfla committed Aug 2, 2024
1 parent 5363fa2 commit b006826
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 9 additions & 2 deletions friends/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ class Meta:
fields = ["name", "profile_img", "reliability"]


class FriendSerializer(serializers.ModelSerializer):
class FriendRequestSerializer(serializers.ModelSerializer):
user = UserSerializer(read_only=True)

class Meta:
model = Friend
fields = ["user", "state"]


class FriendSerializer(serializers.ModelSerializer):
friend = UserSerializer(read_only=True)

class Meta:
model = Friend
fields = ["user", "friend", "state"]
fields = ["friend", "state"]


class RestaurantSerializer(serializers.ModelSerializer):
Expand Down
10 changes: 5 additions & 5 deletions friends/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# from django.contrib.auth.decorators import login_required
from restaurants.models import UserRestaurantsList
from .serializers import RestaurantSerializer, FriendSerializer
from .serializers import RestaurantSerializer, FriendSerializer, FriendRequestSerializer
from accounts.models import User
from .models import Friend
from django.views.decorators.csrf import csrf_exempt
Expand Down Expand Up @@ -36,14 +36,14 @@ def friend_list(request):
user = User.objects.get(id=21)

friend_request = Friend.objects.filter(friend=user, state="request")
friend_request_serialized = FriendSerializer(friend_request, many=True).data
friend_request_serialized = FriendRequestSerializer(friend_request, many=True).data

friend_approve = Friend.objects.filter(user=user, state="approve")
friend_approve_serialized = FriendSerializer(friend_approve, many=True).data
friends = Friend.objects.filter(user=user, state="approve")
friends_serialized = FriendSerializer(friends, many=True).data

data = {
"friend_request": friend_request_serialized,
"friends": friend_approve_serialized,
"friends": friends_serialized,
}

return Response(data)

0 comments on commit b006826

Please sign in to comment.