From 1467d965dc8f428dc1946a1f4f7c0e749b20e570 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Wed, 15 Dec 2021 22:42:32 +0100 Subject: repair group api bug --- chat_api/models.py | 4 ++-- chat_api/serializers.py | 5 +++++ chat_api/views.py | 5 +++-- index.http | 8 ++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/chat_api/models.py b/chat_api/models.py index 3a3f51e..c3b44b6 100644 --- a/chat_api/models.py +++ b/chat_api/models.py @@ -4,7 +4,7 @@ from django.db.models.base import Model class Dm(models.Model): sender = models.ForeignKey(User, related_name="sender_dm", on_delete=models.CASCADE) - reciever = models.ForeignKey(User, related_name="receiver_dm", on_delete=models.CASCADE) + receiver = models.ForeignKey(User, related_name="receiver_dm", on_delete=models.CASCADE) message = models.TextField(null=False) create_date = models.DateTimeField(auto_now=True) @@ -22,7 +22,7 @@ class Group(models.Model): class Gm(models.Model): sender = models.ForeignKey(User, related_name="sender_gm", on_delete=models.CASCADE) - reciever = models.ForeignKey(Group, related_name="receiver_gm", on_delete=models.CASCADE) + receiver = models.ForeignKey(Group, related_name="receiver_gm", on_delete=models.CASCADE) message = models.TextField(null=False) create_date = models.DateTimeField(auto_now=True) diff --git a/chat_api/serializers.py b/chat_api/serializers.py index dee0c45..d182876 100644 --- a/chat_api/serializers.py +++ b/chat_api/serializers.py @@ -31,6 +31,11 @@ class DmSerializer(serializers.ModelSerializer): model = Dm fields = '__all__' +class GmSimpleSerializer(serializers.ModelSerializer): + class Meta: + model = Gm + fields = '__all__' + class GmSerializer(serializers.ModelSerializer): is_mine = serializers.SerializerMethodField('_is_mine') sender = UserSerializer(read_only=True) diff --git a/chat_api/views.py b/chat_api/views.py index 3ea0e54..6783eba 100644 --- a/chat_api/views.py +++ b/chat_api/views.py @@ -12,6 +12,7 @@ from django.db.models.query import Q from .models import * from .serializers import * +from auth_api.serializers import UserSerializer def set_users(request): @@ -108,8 +109,8 @@ class GmsView(APIView): raise Http404 request.data['sender'] = request.user.pk - request.data['reciever'] = pk - serializer = GmSerializer(data=request.data) + request.data['receiver'] = pk + serializer = GmSimpleSerializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save() diff --git a/index.http b/index.http index ef0ba9f..214c9f5 100644 --- a/index.http +++ b/index.http @@ -31,10 +31,14 @@ content-type: application/json ### GET http://localhost:8000/api/auth/info/? -Authorization: Token bd057a90565d85b2efa23f73deb9e5afdb4e4d56b24ba405a1cf33b66b49f4ed +Authorization: Token 050b960ef361d319cd5ed628d3cefa6fee480fdf710bed54d79d4b2b2fb6c936 ### -GET http://localhost:8000/api/chat/groups/detail/22/messages/ +POST http://localhost:8000/api/chat/groups/detail/22/messages/ Authorization: Token b4bd0a69d9f78c9447b4f7581a8b8cc53f5732a7f6542db9a5fea093ce734b2c content-type: application/json + +{ + "message": "test" +} -- cgit v1.2.3