diff --git a/api/serializers.py b/api/serializers.py index e56a745..f2ee9e8 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -11,6 +11,20 @@ class Meta: fields = ["username", "first_name", "last_name", "email"] +# Only used for swagger definitions +class UserLoggedInSerializer(serializers.Serializer): + logged_in = serializers.BooleanField() + login_url = serializers.URLField(max_length=200) + logout_url = serializers.URLField(max_length=200) + user_id = serializers.IntegerField() + username = serializers.CharField() + first_name = serializers.CharField() + last_name = serializers.CharField() + email = serializers.CharField() + organisation = serializers.CharField() + kvk = serializers.CharField() + + class ImportTaskSerializer(UrlFieldMixin, serializers.ModelSerializer): class Meta: model = api_models.ImportTask diff --git a/api/views.py b/api/views.py index dd5b0c3..fb561d0 100644 --- a/api/views.py +++ b/api/views.py @@ -2,6 +2,7 @@ from django.contrib.auth.models import User from django.shortcuts import redirect from django_filters.rest_framework import DjangoFilterBackend +from drf_yasg.utils import swagger_auto_schema from rest_framework import generics, permissions, status, views, viewsets from rest_framework.decorators import action from rest_framework.response import Response @@ -60,11 +61,14 @@ def get_queryset(self): return queryset + @swagger_auto_schema( + responses={200: serializers.UserLoggedInSerializer()}, + ) @action( detail=False, url_path="logged-in", ) - def logged_in(self, request): + def logged_in(self, request) -> Response: """Endpoint to check whether the use is logged in or not.""" user = self.request.user if user.is_anonymous: