Dashboard-XRoom/core/views/AssetBundle.py
2025-05-25 16:38:21 +03:30

28 lines
1.2 KiB
Python

# views.py
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.AssignRoomUser import AssignRoomUser
from core.models.AssetBundleRoom import AssetBundleRoom
from core.serializers.AssetBundleRoomSerializer import AssetBundleRoomSerializer
@api_view(['GET'])
@authentication_classes([SessionAuthentication, TokenAuthentication])
@permission_classes([IsAuthenticated])
def getAssignedAssetBundleRooms(request):
# Get all asset bundle rooms associated with the authenticated user
assigned_rooms = AssignRoomUser.objects.filter(user=request.user).values_list('assetbundle_room', flat=True)
# Fetch all AssetBundleRoom objects that the user is assigned to
rooms = AssetBundleRoom.objects.filter(id__in=assigned_rooms)
# Serialize the rooms
serializer = AssetBundleRoomSerializer(rooms, many=True)
# Return the serialized data as a response
return Response({
"assetbundle_rooms": serializer.data
}, status=status.HTTP_200_OK)