summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chat_api/models.py4
-rw-r--r--chat_api/serializers.py5
-rw-r--r--chat_api/views.py5
-rw-r--r--index.http8
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
5class Dm(models.Model): 5class 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
23class Gm(models.Model): 23class 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
34class GmSimpleSerializer(serializers.ModelSerializer):
35 class Meta:
36 model = Gm
37 fields = '__all__'
38
34class GmSerializer(serializers.ModelSerializer): 39class 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
13from .models import * 13from .models import *
14from .serializers import * 14from .serializers import *
15from auth_api.serializers import UserSerializer
15 16
16 17
17def set_users(request): 18def 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
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
31### 31###
32 32
33GET http://localhost:8000/api/auth/info/? 33GET http://localhost:8000/api/auth/info/?
34Authorization: Token bd057a90565d85b2efa23f73deb9e5afdb4e4d56b24ba405a1cf33b66b49f4ed 34Authorization: Token 050b960ef361d319cd5ed628d3cefa6fee480fdf710bed54d79d4b2b2fb6c936
35 35
36### 36###
37 37
38GET http://localhost:8000/api/chat/groups/detail/22/messages/ 38POST http://localhost:8000/api/chat/groups/detail/22/messages/
39Authorization: Token b4bd0a69d9f78c9447b4f7581a8b8cc53f5732a7f6542db9a5fea093ce734b2c 39Authorization: Token b4bd0a69d9f78c9447b4f7581a8b8cc53f5732a7f6542db9a5fea093ce734b2c
40content-type: application/json 40content-type: application/json
41
42{
43 "message": "test"
44}