Skip to content

Commit

Permalink
Added user_id view
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDyakonov committed Jun 16, 2024
1 parent 4ac7deb commit c72ee11
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions backend/apps/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ class Meta:
]


class UserDetailSerializer(serializers.ModelSerializer):
place_name = serializers.CharField(source="place.name", read_only=True)
place_id = serializers.IntegerField(source="place.id", read_only=True)

class Meta:
model = User
fields = [
"email",
"place_name",
"place_id",
"first_name",
"middle_name",
"last_name",
"is_active",
]


class UserRegistrationSerializer(serializers.ModelSerializer):
password = serializers.CharField(
write_only=True, required=True, style={"input_type": "password"}
Expand Down
3 changes: 2 additions & 1 deletion backend/apps/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
TokenVerifyView,
)

from .views import UserListView, UserRegistrationView
from .views import UserDetailView, UserListView, UserRegistrationView

urlpatterns = [
path("token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
path("token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
path("token/verify/", TokenVerifyView.as_view(), name="token_verify"),
path("", UserListView.as_view(), name="user-list"),
path("register/", UserRegistrationView.as_view(), name="register"),
path("<int:id>/", UserDetailView.as_view(), name="user-detail"),
]
12 changes: 11 additions & 1 deletion backend/apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
from rest_framework import generics

from .models import User
from .serializers import UserListSerializer, UserRegistrationSerializer
from .serializers import (
UserDetailSerializer,
UserListSerializer,
UserRegistrationSerializer,
)


class UserListView(generics.ListAPIView):
Expand All @@ -13,3 +17,9 @@ class UserListView(generics.ListAPIView):
class UserRegistrationView(generics.CreateAPIView):
queryset = User.objects.all()
serializer_class = UserRegistrationSerializer


class UserDetailView(generics.RetrieveAPIView):
queryset = User.objects.all()
serializer_class = UserDetailSerializer
lookup_field = "id"

0 comments on commit c72ee11

Please sign in to comment.