mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-04 17:24:34 +00:00
get spaces
This commit is contained in:
parent
0d4c208ecd
commit
ee7fcf8376
|
@ -2,7 +2,12 @@
|
|||
from rest_framework import serializers
|
||||
from core.models.Space import Space
|
||||
|
||||
from core.serializers.AssetBundleRoomSerializer import AssetBundleRoomSerializer
|
||||
|
||||
class SpaceSerializer(serializers.ModelSerializer):
|
||||
|
||||
assetBundleRoomId = AssetBundleRoomSerializer() # Nested serializer for AssetBundleRoom
|
||||
|
||||
class Meta:
|
||||
model = Space
|
||||
fields = ['userId', 'assetBundleRoomId', 'name', 'description', 'capacity']
|
||||
|
|
|
@ -13,14 +13,15 @@ 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
|
||||
# Get the spaces associated with the authenticated user and join with AssetBundleRoom data
|
||||
spaces = Space.objects.filter(userId=request.user).select_related('assetBundleRoomId')
|
||||
|
||||
# Serialize the spaces
|
||||
# Serialize the spaces and include all fields from the related AssetBundleRoom
|
||||
serializer = SpaceSerializer(spaces, many=True)
|
||||
|
||||
# Return the serialized data as a response
|
||||
|
|
Loading…
Reference in New Issue
Block a user