Dashboard-XRoom/core/views/spaceView.py

30 lines
1.0 KiB
Python
Raw Normal View History

2025-05-25 13:08:21 +00:00
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
2025-05-27 08:50:55 +00:00
2025-05-25 13:08:21 +00:00
@api_view(['GET'])
@authentication_classes([SessionAuthentication, TokenAuthentication])
@permission_classes([IsAuthenticated])
def getSpaces(request):
2025-05-27 08:50:55 +00:00
# Get the spaces associated with the authenticated user and join with AssetBundleRoom data
spaces = Space.objects.filter(userId=request.user).select_related('assetBundleRoomId')
2025-05-25 13:08:21 +00:00
2025-05-27 08:50:55 +00:00
# Serialize the spaces and include all fields from the related AssetBundleRoom
2025-05-25 13:08:21 +00:00
serializer = SpaceSerializer(spaces, many=True)
# Return the serialized data as a response
return Response({
"spaces": serializer.data
}, status=status.HTTP_200_OK)