mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-03 16:54:35 +00:00
29 lines
942 B
Python
29 lines
942 B
Python
from rest_framework.decorators import api_view, authentication_classes, permission_classes
|
|
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
from core.models.Space import Space
|
|
from core.serializers.SpaceSerializer import SpaceSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['GET'])
|
|
@authentication_classes([SessionAuthentication, TokenAuthentication])
|
|
@permission_classes([IsAuthenticated])
|
|
def getSpaces(request):
|
|
# Get the spaces associated with the authenticated user
|
|
spaces = Space.objects.filter(userId=request.user) # Filter spaces by the authenticated user
|
|
|
|
# Serialize the spaces
|
|
serializer = SpaceSerializer(spaces, many=True)
|
|
|
|
# Return the serialized data as a response
|
|
return Response({
|
|
"spaces": serializer.data
|
|
}, status=status.HTTP_200_OK) |