From 7158cef12240607650beba6d4f22a39849298ee0 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sun, 2 Feb 2020 02:10:33 +0100 Subject: [PATCH] WIP user profile api --- api/urls.py | 3 ++- api/views.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/api/urls.py b/api/urls.py index 408cad4..730a13e 100644 --- a/api/urls.py +++ b/api/urls.py @@ -2,7 +2,7 @@ from django.conf.urls import include, url from rest_framework import routers from .views import ContestViewSet, BandViewSet, FrequencyViewSet, EntryCategoryViewSet, ReferenceViewSet, QSOViewSet, \ - ShadowCallViewSet + ShadowCallViewSet, UserProfileView router = routers.DefaultRouter() router.register('contests', ContestViewSet) @@ -12,6 +12,7 @@ router.register('entrycategories', EntryCategoryViewSet) router.register('references', ReferenceViewSet) router.register('qsos', QSOViewSet, basename='qso') router.register('shadowcalls', ShadowCallViewSet) +router.register('profile', UserProfileView, basename='profile') urlpatterns = [ url(r'^', include(router.urls)), diff --git a/api/views.py b/api/views.py index 86d5cae..a6a9c97 100644 --- a/api/views.py +++ b/api/views.py @@ -1,9 +1,10 @@ from rest_framework import viewsets +from rest_framework.views import APIView from rest_framework.permissions import IsAuthenticated, IsAdminUser - +from rest_framework.response import Response from .serializers import ContestSerializer, BandSerializer, FrequencySerializer, EntryCategorySerializer, \ - ReferenceSerializer, QSOSerializer, ShadowCallSerializer + ReferenceSerializer, QSOSerializer, ShadowCallSerializer, UserSerializer from contest.models import Contest, Band, Frequency, EntryCategory, Reference, QSO, ShadowCall @@ -41,9 +42,13 @@ class QSOViewSet(viewsets.ReadOnlyModelViewSet): return QSO.objects.filter(owner=self.request.user) -class UserProfile(viewsets.ReadOnlyModelViewSet): - """Return the currently authenticated user as a single item""" - pass +class UserProfileView(APIView): + permission_classes = [IsAuthenticated] + + def get(self, request, format=None): + user = request.user + serializer = UserSerializer(user) + return Response(serializer.data) class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet):