Skip to content

Commit

Permalink
Merge pull request #42 from nens/user-typehint
Browse files Browse the repository at this point in the history
changed user logged in endpoint for swagger typehinting
  • Loading branch information
JJFlorian authored Apr 8, 2024
2 parents 6318be6 + 6dc2cb8 commit e99ac5d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e99ac5d

Please sign in to comment.