Skip to content

Commit

Permalink
#69 feat : make Friend Api Get method(find friend) (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
0321minji authored Aug 22, 2024
1 parent 96323c5 commit 10d0d8d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cognisle/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
path('admin/', admin.site.urls),
path('users/',include('users.urls')),
path('lands/',include('lands.urls')),
path('friends/',include('friends.urls')),
]
8 changes: 8 additions & 0 deletions friends/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from .views import *

app_name = "friends"

urlpatterns=[
path('',FriendApi.as_view(),name='friends'),
]
45 changes: 44 additions & 1 deletion friends/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
from django.shortcuts import render
from django.shortcuts import get_object_or_404, render
from rest_framework.views import APIView
from rest_framework import serializers, status
from rest_framework.response import Response
from rest_framework.permissions import AllowAny, IsAuthenticated
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema

from users.models import User

# Create your views here.
class FriendApi(APIView):
permission_classes = (IsAuthenticated,)

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

class FindFriendOutputSerializer(serializers.Serializer):
name=serializers.CharField()
email=serializers.EmailField()

def get(self,request):
serializers=self.FindFriendInputSerializer(data=request.query_params)
serializers.is_valid(raise_exception=True)
email=serializers.validated_data.get('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':'success',
'data':output_serializer.data,
})

0 comments on commit 10d0d8d

Please sign in to comment.