Skip to content

Commit

Permalink
#69 : make friends list api (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
0321minji authored Aug 24, 2024
1 parent c31fecb commit abaab71
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions friends/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,37 @@ class FindFriendOutputSerializer(serializers.Serializer):
#친구 검색하기
def get(self,request):
serializers=self.FindFriendInputSerializer(data=request.query_params)
serializers.is_valid(raise_exception=True)
serializers.is_valid()
email=serializers.validated_data.get('email')
user=get_object_or_404(User,email=email)

if user==request.user:
print('here')
if email:
user=get_object_or_404(User,email=email)

if user==request.user:
print('here')
return Response({
'status':'fail',
'data':"자기 자신을 검색할 수 없습니다.",
})

user_data = {
'name': user.name,
'email': user.email,
}

output_serializer=self.FindFriendOutputSerializer(data=user_data)
output_serializer.is_valid(raise_exception=True)

return Response({
'status':'fail',
'data':"자기 자신을 검색할 수 없습니다.",
})

user_data = {
'name': user.name,
'email': user.email,
}

output_serializer=self.FindFriendOutputSerializer(data=user_data)
output_serializer.is_valid(raise_exception=True)

return Response({
'status':'success',
'data':output_serializer.data,
},status=status.HTTP_200_OK)
'status':'success',
'data':output_serializer.data,
},status=status.HTTP_200_OK)
else:
friend = get_object_or_404(Friend, user=request.user)
serializer = self.FindFriendOutputSerializer(friend.friends.all(), many=True)
return Response({
"status": "success",
"data": serializer.data
},status=status.HTTP_200_OK)

#친구 신청 보내기
def post(self,request):
Expand Down Expand Up @@ -170,6 +178,7 @@ def post(self,request):
# }
# }
}, status=status.HTTP_200_OK)

class RequestApi(APIView):
permission_classes=(IsAuthenticated,)

Expand Down

0 comments on commit abaab71

Please sign in to comment.