mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-03 16:54:35 +00:00
29 lines
1.3 KiB
Python
29 lines
1.3 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 or Private=False)
|
|
rooms = AssetBundleRoom.objects.filter(id__in=assigned_rooms ) | AssetBundleRoom.objects.filter(Private=False )
|
|
|
|
# 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)
|