diff options
-rw-r--r-- | auth_api/views.py | 12 | ||||
-rw-r--r-- | chat_api/models.py | 2 | ||||
-rw-r--r-- | chat_api/views.py | 3 | ||||
-rw-r--r-- | index.http | 34 | ||||
-rw-r--r-- | rest.http | 12 |
5 files changed, 60 insertions, 3 deletions
diff --git a/auth_api/views.py b/auth_api/views.py index cd32914..36fc7e0 100644 --- a/auth_api/views.py +++ b/auth_api/views.py | |||
@@ -2,6 +2,7 @@ from django.contrib.auth import login | |||
2 | from django.contrib.auth.models import User | 2 | from django.contrib.auth.models import User |
3 | from django.http.response import Http404 | 3 | from django.http.response import Http404 |
4 | from django.shortcuts import get_object_or_404 | 4 | from django.shortcuts import get_object_or_404 |
5 | from django.db.models import Q | ||
5 | 6 | ||
6 | from rest_framework import permissions | 7 | from rest_framework import permissions |
7 | from rest_framework.authtoken.serializers import AuthTokenSerializer | 8 | from rest_framework.authtoken.serializers import AuthTokenSerializer |
@@ -47,6 +48,15 @@ class UserInfo(APIView): | |||
47 | def get(self, request): | 48 | def get(self, request): |
48 | user = request.GET.get("pk", request.user) | 49 | user = request.GET.get("pk", request.user) |
49 | username = request.GET.get("username", None) | 50 | username = request.GET.get("username", None) |
51 | all_users = request.GET.get("all", None) | ||
52 | |||
53 | if all_users: | ||
54 | users = User.objects.filter(~Q(username=request.user.username)) | ||
55 | serializer = UserSerializer(users, many=True) | ||
56 | |||
57 | return Response(data={ | ||
58 | "users": serializer.data | ||
59 | }) | ||
50 | 60 | ||
51 | if username: | 61 | if username: |
52 | users = User.objects.filter(username__startswith = username)[:5] | 62 | users = User.objects.filter(username__startswith = username)[:5] |
@@ -66,4 +76,4 @@ class UserInfo(APIView): | |||
66 | 76 | ||
67 | return Response({ | 77 | return Response({ |
68 | "user": serializer.data | 78 | "user": serializer.data |
69 | }) \ No newline at end of file | 79 | }) |
diff --git a/chat_api/models.py b/chat_api/models.py index 4c370fc..4b354f4 100644 --- a/chat_api/models.py +++ b/chat_api/models.py | |||
@@ -24,4 +24,4 @@ class Gm(models.Model): | |||
24 | create_date = models.DateTimeField(auto_now=True) | 24 | create_date = models.DateTimeField(auto_now=True) |
25 | 25 | ||
26 | def __str__(self): | 26 | def __str__(self): |
27 | return str(self.sender) \ No newline at end of file | 27 | return str(self.sender) |
diff --git a/chat_api/views.py b/chat_api/views.py index 6d161c1..3ea0e54 100644 --- a/chat_api/views.py +++ b/chat_api/views.py | |||
@@ -63,6 +63,7 @@ class GroupDetailView(generics.RetrieveUpdateDestroyAPIView): | |||
63 | def update(self, request, *args, **kwargs): | 63 | def update(self, request, *args, **kwargs): |
64 | request.data['owner'] = request.user.pk | 64 | request.data['owner'] = request.user.pk |
65 | set_users(request) | 65 | set_users(request) |
66 | |||
66 | return super().update(request, *args, **kwargs) | 67 | return super().update(request, *args, **kwargs) |
67 | 68 | ||
68 | def retrieve(self, request, pk): | 69 | def retrieve(self, request, pk): |
@@ -112,4 +113,4 @@ class GmsView(APIView): | |||
112 | serializer.is_valid(raise_exception=True) | 113 | serializer.is_valid(raise_exception=True) |
113 | serializer.save() | 114 | serializer.save() |
114 | 115 | ||
115 | return Response(serializer.data) \ No newline at end of file | 116 | return Response(serializer.data) |
diff --git a/index.http b/index.http new file mode 100644 index 0000000..6349a84 --- /dev/null +++ b/index.http | |||
@@ -0,0 +1,34 @@ | |||
1 | POST http://localhost:8000/api/auth/login/ | ||
2 | content-type: application/json | ||
3 | |||
4 | { | ||
5 | "username": "jakub", | ||
6 | "password": "jakub" | ||
7 | } | ||
8 | |||
9 | ### | ||
10 | |||
11 | PUT http://localhost:8000/api/chat/groups/detail/1/ | ||
12 | Authorization: Token bd057a90565d85b2efa23f73deb9e5afdb4e4d56b24ba405a1cf33b66b49f4ed | ||
13 | content-type: application/json | ||
14 | |||
15 | { | ||
16 | "name": "Bar", | ||
17 | "users": [2] | ||
18 | } | ||
19 | |||
20 | ### | ||
21 | |||
22 | POST http://localhost:8000/api/chat/groups/ | ||
23 | Authorization: Token bd057a90565d85b2efa23f73deb9e5afdb4e4d56b24ba405a1cf33b66b49f4ed | ||
24 | content-type: application/json | ||
25 | |||
26 | { | ||
27 | "name": "Foo" | ||
28 | } | ||
29 | |||
30 | |||
31 | ### | ||
32 | |||
33 | GET http://localhost:8000/api/auth/info/? | ||
34 | Authorization: Token bd057a90565d85b2efa23f73deb9e5afdb4e4d56b24ba405a1cf33b66b49f4ed | ||
diff --git a/rest.http b/rest.http new file mode 100644 index 0000000..b0c6198 --- /dev/null +++ b/rest.http | |||
@@ -0,0 +1,12 @@ | |||
1 | POST http://localhost:8000/api/auth/login/ | ||
2 | content-type: application/json | ||
3 | |||
4 | { | ||
5 | "username": "admin", | ||
6 | "password": "admin" | ||
7 | } | ||
8 | |||
9 | ### | ||
10 | |||
11 | GET http://localhost:8000/api/auth/info?username=a | ||
12 | authorization: TOKEN 92844a78767178dfc15b0814373839bc80b97028f433440fcb4223088a9b8b69 | ||