Skip to content

Commit

Permalink
#69 feat: make request reject api (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
0321minji authored Aug 23, 2024
1 parent 0f3fceb commit cfeb2a0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions friends/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
urlpatterns=[
path('',FriendApi.as_view(),name='friends'),
path('request/accept/',AcceptRequestApi.as_view(),name='request_accept'),
path('request/reject/',RejectRequestApi.as_view(),name='request_reject'),

]
41 changes: 41 additions & 0 deletions friends/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,45 @@ def post(self,request):
"email": request.user.email
}
}
}, status=status.HTTP_200_OK)

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

class RejectRequestInputSerializer(serializers.Serializer):
email=serializers.EmailField()

def post(self,request):
serializers=self.RejectRequestInputSerializer(data=request.data)
serializers.is_valid(raise_exception=True)
email=serializers.validated_data.get('email')
from_user=get_object_or_404(User,email=email)
friend_request=FriendRequest.objects.filter(from_user=from_user,to_user=request.user).first()

if not friend_request:
return Response({
"status": "fail",
"message": "해당 요청이 존재하지 않습니다."
}, status=status.HTTP_404_NOT_FOUND)

try:
friend_request.reject()
except Exception as e:
return Response({
"status": "fail",
"message": str(e)
}, status=status.HTTP_400_BAD_REQUEST)

return Response({
"status": "success",
# "data": {
# "from_user": {
# "name": from_user.name,
# "email": from_user.email
# },
# "to_user": {
# "name": request.user.name,
# "email": request.user.email
# }
# }
}, status=status.HTTP_200_OK)
1 change: 0 additions & 1 deletion lands/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.shortcuts import render
from django.shortcuts import get_object_or_404
from django.db import transaction
from django.db import transaction
from rest_framework.views import APIView
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework import serializers, status
Expand Down

0 comments on commit cfeb2a0

Please sign in to comment.