From cb9a4aad523d568b772fdfe3cea5f4e882aefecf Mon Sep 17 00:00:00 2001 From: Cody Date: Wed, 7 Jan 2026 20:14:51 +0800 Subject: [PATCH] Backend user endpoint setup --- server/user_profile/urls.py | 1 + server/user_profile/views.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/server/user_profile/urls.py b/server/user_profile/urls.py index e89b0dd..44292f5 100644 --- a/server/user_profile/urls.py +++ b/server/user_profile/urls.py @@ -7,4 +7,5 @@ path("profile//", views.UserProfileDetail.as_view(), name="profile-detail"), path("profile/", views.UserProfileList.as_view(), name="profile-list"), path("", views.UserList.as_view(), name="user-list"), + path("me/", views.MeView.as_view(), name="me"), ] \ No newline at end of file diff --git a/server/user_profile/views.py b/server/user_profile/views.py index edbd78c..46a8c14 100644 --- a/server/user_profile/views.py +++ b/server/user_profile/views.py @@ -14,7 +14,7 @@ class UserList(APIView): - permission_classes = (permissions.IsAuthenticated) + permission_classes = (permissions.IsAuthenticated,) def get(self, request): users = User.objects.all() @@ -30,5 +30,23 @@ class UserProfileDetail(generics.RetrieveUpdateAPIView): permission_classes = (permissions.IsAuthenticated, IsUserOrReadOnly) queryset = Profile.objects.all() serializer_class = ProfileSerializer + +class MeView(APIView): + permission_classes = (permissions.IsAuthenticated,) + + def get(self, request): + user = request.user + profile = Profile.objects.get(user=user) + + return Response({ + "id": user.id, + "username": user.username, + "email": user.email, + "first_name": user.first_name, + "last_name": user.last_name, + "phone_number": profile.phone_number, + "date_of_birth": profile.date_of_birth, + "address": profile.address, + })