mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-05 17:54:33 +00:00
Compare commits
8 Commits
ee7fcf8376
...
d8da0aa5c3
Author | SHA1 | Date | |
---|---|---|---|
d8da0aa5c3 | |||
c6d10ee015 | |||
41c78f2971 | |||
ef3e03f22c | |||
e630622529 | |||
d96eb8f498 | |||
7ccaed7313 | |||
55c7e15d59 |
|
@ -2,7 +2,9 @@
|
|||
from rest_framework import serializers
|
||||
from core.models.AssetBundleRoom import AssetBundleRoom
|
||||
|
||||
|
||||
|
||||
class AssetBundleRoomSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = AssetBundleRoom
|
||||
fields = ['id', 'name', 'description' , 'img','url' , 'Private' , 'maxPerson'] # Include the fields you want to return
|
||||
fields = '__all__' # This will include all fields from the AssetBundleRoom model
|
|
@ -1,13 +1,25 @@
|
|||
# serializers.py
|
||||
from rest_framework import serializers
|
||||
from core.models.Space import Space
|
||||
from core.models.AssetBundleRoom import AssetBundleRoom # Import AssetBundleRoom
|
||||
|
||||
from core.serializers.AssetBundleRoomSerializer import AssetBundleRoomSerializer
|
||||
|
||||
class SpaceSerializer(serializers.ModelSerializer):
|
||||
class SpaceSerializerforadd(serializers.ModelSerializer):
|
||||
|
||||
assetBundleRoomId = AssetBundleRoomSerializer() # Nested serializer for AssetBundleRoom
|
||||
# assetBundleRoomId = AssetBundleRoomSerializer() # Nested serializer for AssetBundleRoom
|
||||
assetBundleRoomId = serializers.PrimaryKeyRelatedField(queryset=AssetBundleRoom.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = Space
|
||||
fields = ['userId', 'assetBundleRoomId', 'name', 'description', 'capacity']
|
||||
fields = ['userId', 'assetBundleRoomId', 'name', 'description', 'capacity' ]
|
||||
|
||||
|
||||
|
||||
|
||||
class SpaceSerializer(serializers.ModelSerializer):
|
||||
assetBundleRoomId = AssetBundleRoomSerializer() # Nested serializer to include all fields from AssetBundleRoom
|
||||
|
||||
class Meta:
|
||||
model = Space
|
||||
fields = '__all__' # You can adjust which fields from Space to include if needed
|
|
@ -50,7 +50,7 @@ urlpatterns = [
|
|||
re_path('add_subscription', userView.addSubscription),
|
||||
re_path('add_teamMember', userView.addTeamMember),
|
||||
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_assigned_assetbundle_rooms', AssetBundle.getAssignedAssetBundleRooms , name='get_assigned_assetbundle_rooms'),
|
||||
|
|
|
@ -4,8 +4,8 @@ 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
|
||||
|
||||
from core.models.AssetBundleRoom import AssetBundleRoom
|
||||
from core.serializers.SpaceSerializer import SpaceSerializer , SpaceSerializerforadd
|
||||
|
||||
|
||||
|
||||
|
@ -22,9 +22,49 @@ def getSpaces(request):
|
|||
spaces = Space.objects.filter(userId=request.user).select_related('assetBundleRoomId')
|
||||
|
||||
# Serialize the spaces and include all fields from the related AssetBundleRoom
|
||||
# Pass 'assetBundleRoomId' as it will be automatically included by select_related
|
||||
serializer = SpaceSerializer(spaces, many=True)
|
||||
|
||||
# Return the serialized data as a response
|
||||
return Response({
|
||||
"spaces": serializer.data
|
||||
}, 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.id
|
||||
|
||||
# Pass the request object to the serializer context
|
||||
serializer = SpaceSerializerforadd(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)
|
||||
|
|
|
@ -1152,35 +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
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ Authorization: token 8dcae0063521ca707a9d0ab6ce3d4794a90064ca
|
|||
|
||||
POST http://my.xroomapp.com:8000/add_space
|
||||
Content-Type: application/json
|
||||
Authorization: token 8dcae0063521ca707a9d0ab6ce3d4794a90064ca
|
||||
Authorization: token a6e1d5db61c4e8b2a0a4c0b623915e3b3a68df40
|
||||
|
||||
{ "assetBundleRoomId": "1", "name":"ROOM1", "description":"TEST DES", "capacity": "12" }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user