get spaces

This commit is contained in:
mi1468 2025-05-27 14:49:54 +03:30
parent ef3e03f22c
commit 41c78f2971
3 changed files with 41 additions and 37 deletions

View File

@ -50,7 +50,7 @@ urlpatterns = [
re_path('add_subscription', userView.addSubscription), re_path('add_subscription', userView.addSubscription),
re_path('add_teamMember', userView.addTeamMember), re_path('add_teamMember', userView.addTeamMember),
re_path('get_team_member_info', userView.get_team_member_info), re_path('get_team_member_info', userView.get_team_member_info),
re_path('add_space', userView.addSpace), re_path('add_space', spaceView.addSpace),
re_path('get_space', spaceView.getSpaces), re_path('get_space', spaceView.getSpaces),
re_path('get_assigned_assetbundle_rooms', AssetBundle.getAssignedAssetBundleRooms , name='get_assigned_assetbundle_rooms'), re_path('get_assigned_assetbundle_rooms', AssetBundle.getAssignedAssetBundleRooms , name='get_assigned_assetbundle_rooms'),

View File

@ -4,6 +4,7 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from core.models.Space import Space from core.models.Space import Space
from core.models.AssetBundleRoom import AssetBundleRoom
from core.serializers.SpaceSerializer import SpaceSerializer from core.serializers.SpaceSerializer import SpaceSerializer
@ -28,3 +29,42 @@ def getSpaces(request):
return Response({ return Response({
"spaces": serializer.data "spaces": serializer.data
}, status=status.HTTP_200_OK) }, status=status.HTTP_200_OK)
@api_view(['POST'])
@authentication_classes([SessionAuthentication, TokenAuthentication])
@permission_classes([IsAuthenticated])
def addSpace(request):
# Make a mutable copy of the request data
data = request.data.copy()
data['userId'] = request.user.id # Automatically assign the authenticated user
# Retrieve the AssetBundleRoom instance from the provided ID
try:
asset_bundle_room = AssetBundleRoom.objects.get(id=data['assetBundleRoomId'])
except AssetBundleRoom.DoesNotExist:
return Response({"detail": "AssetBundleRoom not found."}, status=status.HTTP_404_NOT_FOUND)
# Assign the AssetBundleRoom instance to the data
data['assetBundleRoomId'] = asset_bundle_room
# Pass the request object to the serializer context
serializer = SpaceSerializer(data=data)
if serializer.is_valid():
# Save the space using the validated data
space = serializer.save() # This automatically saves the space
# Return the response with the space data
return Response({
"message": "Space added successfully.",
"space": serializer.data # This gives you the serialized data of the saved space
}, status=status.HTTP_201_CREATED)
else:
# If validation fails, return the errors
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

View File

@ -1152,39 +1152,3 @@ def get_team_member_info(request):
@api_view(['POST'])
@authentication_classes([SessionAuthentication, TokenAuthentication])
@permission_classes([IsAuthenticated])
def addSpace(request):
# Make a mutable copy of the request data
data = request.data.copy()
data['userId'] = request.user.id # Automatically assign the authenticated user
# Retrieve the AssetBundleRoom instance from the provided ID
try:
asset_bundle_room = AssetBundleRoom.objects.get(id=data['assetBundleRoomId'])
except AssetBundleRoom.DoesNotExist:
return Response({"detail": "AssetBundleRoom not found."}, status=status.HTTP_404_NOT_FOUND)
# Assign the AssetBundleRoom instance to the data
data['assetBundleRoomId'] = asset_bundle_room
# Pass the request object to the serializer context
serializer = SpaceSerializer(data=data)
if serializer.is_valid():
# Save the space using the validated data
space = serializer.save() # This automatically saves the space
# Return the response with the space data
return Response({
"message": "Space added successfully.",
"space": serializer.data # This gives you the serialized data of the saved space
}, status=status.HTTP_201_CREATED)
else:
# If validation fails, return the errors
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)