Skip to content

Commit 81691b1

Browse files
committed
Add /auth/specialists/ endpoint
1 parent 5ea6bb8 commit 81691b1

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

users/urls.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from django.urls import path, re_path
22

3-
43
from users.views import (
54
EmailResetPassword,
65
ResetPassword,
6+
SpecialistsList,
77
UserDetail,
88
UserList,
99
VerifyEmail,
@@ -13,6 +13,9 @@
1313

1414
urlpatterns = [
1515
path("users/", UserList.as_view()),
16+
path(
17+
"specialists/", SpecialistsList.as_view()
18+
), # this url actually returns mentors, experts and investors
1619
path("users/<int:pk>/", UserDetail.as_view()),
1720
path("users/reset-password/", EmailResetPassword.as_view()),
1821
re_path(

users/views.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from datetime import datetime
22

33
import jwt
4-
from core.permissions import IsOwnerOrReadOnly
5-
from core.utils import Email
64
from django.conf import settings
75
from django.contrib.auth import get_user_model
86
from django.contrib.sites.shortcuts import get_current_site
7+
from django.db.models import Q
98
from django.shortcuts import redirect
109
from django.urls import reverse
1110
from django_filters import rest_framework as filters
1211
from rest_framework import status
1312
from rest_framework.generics import (
1413
GenericAPIView,
14+
ListAPIView,
1515
ListCreateAPIView,
1616
RetrieveUpdateDestroyAPIView,
1717
UpdateAPIView,
@@ -20,6 +20,8 @@
2020
from rest_framework.response import Response
2121
from rest_framework_simplejwt.tokens import RefreshToken
2222

23+
from core.permissions import IsOwnerOrReadOnly
24+
from core.utils import Email
2325
from users.serializers import (
2426
EmailSerializer,
2527
PasswordSerializer,
@@ -69,6 +71,18 @@ def post(self, request, *args, **kwargs):
6971
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
7072

7173

74+
class SpecialistsList(ListAPIView):
75+
"""
76+
This view returns a list of specialists: investors, experts and mentors.
77+
"""
78+
79+
queryset = User.objects.filter(
80+
Q(user_type=User.EXPERT) | Q(user_type=User.MENTOR) | Q(user_type=User.INVESTOR)
81+
)
82+
permission_classes = [IsAuthenticated]
83+
serializer_class = UserListSerializer
84+
85+
7286
class UserDetail(RetrieveUpdateDestroyAPIView):
7387
queryset = User.objects.all()
7488
permission_classes = [IsOwnerOrReadOnly, IsAuthenticated]

0 commit comments

Comments
 (0)