serialiser patch
This commit is contained in:
parent
140da78397
commit
ff21682310
@ -5,8 +5,6 @@ from rest_framework.authentication import SessionAuthentication
|
|||||||
|
|
||||||
from chat.models import AskModel
|
from chat.models import AskModel
|
||||||
|
|
||||||
from ..serializers.ask import AskSerializer
|
|
||||||
|
|
||||||
from notice.consumers import notice_manager
|
from notice.consumers import notice_manager
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@ -14,7 +12,6 @@ from django.contrib.auth.models import User
|
|||||||
|
|
||||||
class AskView(APIView):
|
class AskView(APIView):
|
||||||
|
|
||||||
serializer_class = AskSerializer
|
|
||||||
permission_classes = (permissions.IsAuthenticated,)
|
permission_classes = (permissions.IsAuthenticated,)
|
||||||
authentication_classes = (SessionAuthentication,)
|
authentication_classes = (SessionAuthentication,)
|
||||||
|
|
||||||
@ -24,11 +21,15 @@ class AskView(APIView):
|
|||||||
asker_id = request.user.pk
|
asker_id = request.user.pk
|
||||||
asked_id = data["asked"]
|
asked_id = data["asked"]
|
||||||
|
|
||||||
|
print("1")
|
||||||
|
|
||||||
if (asked_id is None):
|
if (asked_id is None):
|
||||||
return Response(status=status.HTTP_400_BAD_REQUEST)
|
return Response(status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
print("2")
|
||||||
|
|
||||||
if AskModel().is_asked(asker_id, asked_id):
|
if AskModel().is_asked(asker_id, asked_id):
|
||||||
return Response(status=status.HTTP_208_ALREADY_REPORTED)
|
return Response(status=status.HTTP_208_ALREADY_REPORTED)
|
||||||
|
print("3")
|
||||||
|
|
||||||
AskModel(asker_id=asker_id, asked_id=asked_id).save()
|
AskModel(asker_id=asker_id, asked_id=asked_id).save()
|
||||||
return Response(status=status.HTTP_201_CREATED)
|
return Response(status=status.HTTP_201_CREATED)
|
||||||
@ -45,8 +46,11 @@ class AskView(APIView):
|
|||||||
if (asked_id is None):
|
if (asked_id is None):
|
||||||
return Response(status=status.HTTP_400_BAD_REQUEST)
|
return Response(status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
print(asker_id, " ", asked_id)
|
||||||
|
print(AskModel().is_asked(2, 1))
|
||||||
|
print(AskModel().is_asked(1, 2))
|
||||||
if not AskModel().is_asked(asker_id, asked_id):
|
if not AskModel().is_asked(asker_id, asked_id):
|
||||||
return Response(status=status.HTTP_404_NOT_FOUND)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
# Don't need more verification, just above is enough
|
# Don't need more verification, just above is enough
|
||||||
asker = User.objects.get(pk=asker_id)
|
asker = User.objects.get(pk=asker_id)
|
||||||
@ -57,10 +61,23 @@ class AskView(APIView):
|
|||||||
|
|
||||||
return Response(status=status.HTTP_200_OK)
|
return Response(status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def get(self, request, pk=None):
|
||||||
|
data: dict = request.data
|
||||||
|
|
||||||
|
asker_id = request.user.pk
|
||||||
|
asked_id = pk
|
||||||
|
|
||||||
|
if (asked_id is None):
|
||||||
|
return Response(status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
if not AskModel().is_asked(asker_id, asked_id):
|
||||||
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
return Response(status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AskAcceptView(APIView):
|
class AskAcceptView(APIView):
|
||||||
|
|
||||||
serializer_class = AskSerializer
|
|
||||||
permission_classes = (permissions.IsAuthenticated,)
|
permission_classes = (permissions.IsAuthenticated,)
|
||||||
authentication_classes = (SessionAuthentication,)
|
authentication_classes = (SessionAuthentication,)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user