diff options
author | jdlugosz963 <jdlugosz963@gmail.com> | 2021-12-15 22:42:32 +0100 |
---|---|---|
committer | jdlugosz963 <jdlugosz963@gmail.com> | 2021-12-15 22:42:32 +0100 |
commit | 1467d965dc8f428dc1946a1f4f7c0e749b20e570 (patch) | |
tree | bbce6eb6440df586e0b0a3466f5128911181a04c | |
parent | e4c0cecb34b159392f95b081916b13534754603d (diff) | |
download | lom_api-1467d965dc8f428dc1946a1f4f7c0e749b20e570.tar.gz lom_api-1467d965dc8f428dc1946a1f4f7c0e749b20e570.zip |
repair group api bug
-rw-r--r-- | chat_api/models.py | 4 | ||||
-rw-r--r-- | chat_api/serializers.py | 5 | ||||
-rw-r--r-- | chat_api/views.py | 5 | ||||
-rw-r--r-- | 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 | |||
4 | 4 | ||
5 | class Dm(models.Model): | 5 | class Dm(models.Model): |
6 | sender = models.ForeignKey(User, related_name="sender_dm", on_delete=models.CASCADE) | 6 | sender = models.ForeignKey(User, related_name="sender_dm", on_delete=models.CASCADE) |
7 | reciever = models.ForeignKey(User, related_name="receiver_dm", on_delete=models.CASCADE) | 7 | receiver = models.ForeignKey(User, related_name="receiver_dm", on_delete=models.CASCADE) |
8 | message = models.TextField(null=False) | 8 | message = models.TextField(null=False) |
9 | create_date = models.DateTimeField(auto_now=True) | 9 | create_date = models.DateTimeField(auto_now=True) |
10 | 10 | ||
@@ -22,7 +22,7 @@ class Group(models.Model): | |||
22 | 22 | ||
23 | class Gm(models.Model): | 23 | class Gm(models.Model): |
24 | sender = models.ForeignKey(User, related_name="sender_gm", on_delete=models.CASCADE) | 24 | sender = models.ForeignKey(User, related_name="sender_gm", on_delete=models.CASCADE) |
25 | reciever = models.ForeignKey(Group, related_name="receiver_gm", on_delete=models.CASCADE) | 25 | receiver = models.ForeignKey(Group, related_name="receiver_gm", on_delete=models.CASCADE) |
26 | message = models.TextField(null=False) | 26 | message = models.TextField(null=False) |
27 | create_date = models.DateTimeField(auto_now=True) | 27 | create_date = models.DateTimeField(auto_now=True) |
28 | 28 | ||
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): | |||
31 | model = Dm | 31 | model = Dm |
32 | fields = '__all__' | 32 | fields = '__all__' |
33 | 33 | ||
34 | class GmSimpleSerializer(serializers.ModelSerializer): | ||
35 | class Meta: | ||
36 | model = Gm | ||
37 | fields = '__all__' | ||
38 | |||
34 | class GmSerializer(serializers.ModelSerializer): | 39 | class GmSerializer(serializers.ModelSerializer): |
35 | is_mine = serializers.SerializerMethodField('_is_mine') | 40 | is_mine = serializers.SerializerMethodField('_is_mine') |
36 | sender = UserSerializer(read_only=True) | 41 | 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 | |||
12 | 12 | ||
13 | from .models import * | 13 | from .models import * |
14 | from .serializers import * | 14 | from .serializers import * |
15 | from auth_api.serializers import UserSerializer | ||
15 | 16 | ||
16 | 17 | ||
17 | def set_users(request): | 18 | def set_users(request): |
@@ -108,8 +109,8 @@ class GmsView(APIView): | |||
108 | raise Http404 | 109 | raise Http404 |
109 | 110 | ||
110 | request.data['sender'] = request.user.pk | 111 | request.data['sender'] = request.user.pk |
111 | request.data['reciever'] = pk | 112 | request.data['receiver'] = pk |
112 | serializer = GmSerializer(data=request.data) | 113 | serializer = GmSimpleSerializer(data=request.data) |
113 | serializer.is_valid(raise_exception=True) | 114 | serializer.is_valid(raise_exception=True) |
114 | serializer.save() | 115 | serializer.save() |
115 | 116 | ||
@@ -31,10 +31,14 @@ content-type: application/json | |||
31 | ### | 31 | ### |
32 | 32 | ||
33 | GET http://localhost:8000/api/auth/info/? | 33 | GET http://localhost:8000/api/auth/info/? |
34 | Authorization: Token bd057a90565d85b2efa23f73deb9e5afdb4e4d56b24ba405a1cf33b66b49f4ed | 34 | Authorization: Token 050b960ef361d319cd5ed628d3cefa6fee480fdf710bed54d79d4b2b2fb6c936 |
35 | 35 | ||
36 | ### | 36 | ### |
37 | 37 | ||
38 | GET http://localhost:8000/api/chat/groups/detail/22/messages/ | 38 | POST http://localhost:8000/api/chat/groups/detail/22/messages/ |
39 | Authorization: Token b4bd0a69d9f78c9447b4f7581a8b8cc53f5732a7f6542db9a5fea093ce734b2c | 39 | Authorization: Token b4bd0a69d9f78c9447b4f7581a8b8cc53f5732a7f6542db9a5fea093ce734b2c |
40 | content-type: application/json | 40 | content-type: application/json |
41 | |||
42 | { | ||
43 | "message": "test" | ||
44 | } | ||