mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-04 17:24:34 +00:00
added assetbundel
This commit is contained in:
parent
8984d6e542
commit
23a765c861
27
core/migrations/0009_space.py
Normal file
27
core/migrations/0009_space.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Generated by Django 5.0 on 2025-05-25 10:50
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0008_assignroomuser'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Space',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('description', models.TextField()),
|
||||
('capacity', models.PositiveIntegerField()),
|
||||
('assetBundleRoomId', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.assetbundleroom')),
|
||||
('userId', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
15
core/models/Space.py
Normal file
15
core/models/Space.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from django.db import models
|
||||
from django.conf import settings
|
||||
from core.models.AssetBundleRoom import AssetBundleRoom # Adjust import path if needed
|
||||
|
||||
|
||||
|
||||
class Space(models.Model):
|
||||
userId = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
assetBundleRoomId = models.ForeignKey(AssetBundleRoom, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=100)
|
||||
description = models.TextField()
|
||||
capacity = models.PositiveIntegerField()
|
||||
|
||||
def __str__(self):
|
||||
return f"Space {self.name} (Capacity: {self.capacity})"
|
8
core/serializers/AssetBundleRoomSerializer.py
Normal file
8
core/serializers/AssetBundleRoomSerializer.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
# serializers.py
|
||||
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'] # Include the fields you want to return
|
8
core/serializers/SpaceSerializer.py
Normal file
8
core/serializers/SpaceSerializer.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
# serializers.py
|
||||
from rest_framework import serializers
|
||||
from core.models.Space import Space
|
||||
|
||||
class SpaceSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Space
|
||||
fields = ['userId', 'assetBundleRoomId', 'name', 'description', 'capacity']
|
|
@ -3,6 +3,8 @@ from django.contrib import admin
|
|||
from django.urls import path
|
||||
|
||||
from .views import userView
|
||||
from .views import spaceView
|
||||
from .views import AssetBundle
|
||||
from django.urls import include, path
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
|
@ -48,7 +50,11 @@ 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('get_space', spaceView.getSpaces),
|
||||
re_path('get_assigned_assetbundle_rooms', AssetBundle.getAssignedAssetBundleRooms , name='get_assigned_assetbundle_rooms'),
|
||||
|
||||
|
||||
|
||||
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
27
core/views/AssetBundle.py
Normal file
27
core/views/AssetBundle.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# 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)
|
29
core/views/spaceView.py
Normal file
29
core/views/spaceView.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
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.Space import Space
|
||||
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
|
||||
|
||||
# Serialize the spaces
|
||||
serializer = SpaceSerializer(spaces, many=True)
|
||||
|
||||
# Return the serialized data as a response
|
||||
return Response({
|
||||
"spaces": serializer.data
|
||||
}, status=status.HTTP_200_OK)
|
|
@ -22,6 +22,7 @@ from core.serializers.VideoSerializer import VideoSerializer
|
|||
from core.serializers.PdfSerializer import PdfSerializer
|
||||
from core.serializers.SubscriptionSerializer import SubscriptionSerializer
|
||||
from core.serializers.TeamMemberSerializer import TeamMemberSerializer
|
||||
from core.serializers.SpaceSerializer import SpaceSerializer
|
||||
|
||||
# utils.py
|
||||
from core.models.AssignedRule import AssignedRule
|
||||
|
@ -1146,4 +1147,40 @@ def get_team_member_info(request):
|
|||
'subscriptionCount': user_subscription_data,
|
||||
},
|
||||
'message': 'موفق'
|
||||
}, 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
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
22
test.rest
22
test.rest
|
@ -95,13 +95,27 @@ Authorization: token 8dcae0063521ca707a9d0ab6ce3d4794a90064ca
|
|||
|
||||
{ "mobile_number": "09140086608", "first_name":"mahdi", "last_name":"arabi", "semat":"modir", "password": "12345678", "isAdmin":"true" }
|
||||
|
||||
|
||||
|
||||
|
||||
###
|
||||
|
||||
|
||||
|
||||
GET http://127.0.0.1:8000/get_team_member_info
|
||||
POST http://127.0.0.1:8000/add_space
|
||||
Content-Type: application/json
|
||||
Authorization: token 8dcae0063521ca707a9d0ab6ce3d4794a90064ca
|
||||
# Authorization: token 53e2b003a92e22aca85c95088a438ece8d9a5dfb
|
||||
|
||||
{ "assetBundleRoomId": "1", "name":"ROOM1", "description":"TEST DES", "capacity": "12" }
|
||||
|
||||
|
||||
|
||||
###
|
||||
GET http://127.0.0.1:8000/get_space
|
||||
Content-Type: application/json
|
||||
Authorization: token 8dcae0063521ca707a9d0ab6ce3d4794a90064ca
|
||||
|
||||
|
||||
###
|
||||
GET http://127.0.0.1:8000/get_assigned_assetbundle_rooms
|
||||
Content-Type: application/json
|
||||
Authorization: token 8dcae0063521ca707a9d0ab6ce3d4794a90064ca
|
||||
|
Loading…
Reference in New Issue
Block a user