diff --git a/backend/apps/accounts/serializers.py b/backend/apps/accounts/serializers.py index 4a2e4e8..97bd1b5 100644 --- a/backend/apps/accounts/serializers.py +++ b/backend/apps/accounts/serializers.py @@ -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"} diff --git a/backend/apps/accounts/urls.py b/backend/apps/accounts/urls.py index 82f61a0..aef15e8 100644 --- a/backend/apps/accounts/urls.py +++ b/backend/apps/accounts/urls.py @@ -5,7 +5,7 @@ TokenVerifyView, ) -from .views import UserListView, UserRegistrationView +from .views import UserDetailView, UserListView, UserRegistrationView urlpatterns = [ path("token/", TokenObtainPairView.as_view(), name="token_obtain_pair"), @@ -13,4 +13,5 @@ path("token/verify/", TokenVerifyView.as_view(), name="token_verify"), path("", UserListView.as_view(), name="user-list"), path("register/", UserRegistrationView.as_view(), name="register"), + path("/", UserDetailView.as_view(), name="user-detail"), ] diff --git a/backend/apps/accounts/views.py b/backend/apps/accounts/views.py index 97806b8..b7ef7ae 100644 --- a/backend/apps/accounts/views.py +++ b/backend/apps/accounts/views.py @@ -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): @@ -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"