mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-02 00:04:34 +00:00
get meeting
This commit is contained in:
parent
17204180c8
commit
24d745958e
|
@ -1,7 +1,78 @@
|
|||
from rest_framework import serializers
|
||||
from core.models.Meeting import Meeting
|
||||
from core.models.customer import Customer
|
||||
from core.serializers.SpaceSerializer import SpaceSerializer
|
||||
from core.serializers.CustomerSerializer import CustomerSerializer
|
||||
from core.serializers.AssetBundleRoomSerializer import AssetBundleRoomSerializer
|
||||
|
||||
|
||||
|
||||
|
||||
class MeetingSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Meeting
|
||||
fields = ['id', 'name', 'description', 'date_time', 'creator_user', 'space', 'asset_bundle', 'use_space']
|
||||
|
||||
|
||||
|
||||
class MeetingSerializerFull(serializers.ModelSerializer):
|
||||
space_data = serializers.SerializerMethodField()
|
||||
asset_bundle_data = serializers.SerializerMethodField()
|
||||
invited_users = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Meeting
|
||||
fields = [
|
||||
'id', 'name', 'description', 'date_time', 'creator_user',
|
||||
'use_space', 'space', 'asset_bundle',
|
||||
'space_data', 'asset_bundle_data', 'invited_users'
|
||||
]
|
||||
|
||||
def get_space_data(self, obj):
|
||||
if obj.use_space and obj.space:
|
||||
return SpaceSerializer(obj.space).data # Replace with your actual Space serializer
|
||||
return None
|
||||
|
||||
def get_asset_bundle_data(self, obj):
|
||||
if not obj.use_space and obj.asset_bundle:
|
||||
return AssetBundleRoomSerializer(obj.asset_bundle).data # Replace with your actual AssetBundle serializer
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def get_invited_users(self, obj):
|
||||
invitations = obj.invitations.select_related('user')
|
||||
result = []
|
||||
|
||||
for invite in invitations:
|
||||
user = invite.user
|
||||
try:
|
||||
customer = Customer.objects.get(user=user)
|
||||
customer_data = CustomerSerializer(customer).data
|
||||
except Customer.DoesNotExist:
|
||||
customer_data = None
|
||||
|
||||
result.append({
|
||||
"id": user.id,
|
||||
"username": user.username,
|
||||
"email": user.email,
|
||||
"customer": customer_data
|
||||
})
|
||||
|
||||
return result
|
||||
# def get_invited_users(self, obj):
|
||||
# invitations = obj.invitations.select_related('user')
|
||||
# return [
|
||||
# {
|
||||
# "id": invite.user.id,
|
||||
# "username": invite.user.username,
|
||||
# "email": invite.user.email,
|
||||
# # add any custom customer fields you want
|
||||
# }
|
||||
# for invite in invitations
|
||||
# ]
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -98,6 +98,7 @@ urlpatterns = [
|
|||
re_path('get_all_team_members', teamView.get_all_team_members),
|
||||
|
||||
path('add_meeting', meetingView. addMeeting, name='add_meeting'),
|
||||
path('get_user_meetings', meetingView. get_user_meetings, name='get_user_meetings'),
|
||||
|
||||
|
||||
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
0
core/utils/__init__.py
Normal file
0
core/utils/__init__.py
Normal file
33
core/utils/sms.py
Normal file
33
core/utils/sms.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def send_sms(to_number, code):
|
||||
username = "09399112092"
|
||||
password = "Dadechin123!@##!"
|
||||
from_number = "+983000505"
|
||||
pattern_code = "lgfrblbdppyn202"
|
||||
|
||||
url = "https://ippanel.com/patterns/pattern"
|
||||
to = [to_number]
|
||||
input_data = {"code": code}
|
||||
|
||||
params = {
|
||||
"username": username,
|
||||
"password": password,
|
||||
"from": from_number,
|
||||
"to": json.dumps(to),
|
||||
"input_data": json.dumps(input_data),
|
||||
"pattern_code": pattern_code
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, params=params, data=input_data)
|
||||
return response.text
|
||||
except Exception as e:
|
||||
return f"Error: {e}"
|
||||
|
|
@ -5,8 +5,10 @@ from rest_framework.response import Response
|
|||
from rest_framework import status
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi
|
||||
from core.serializers.MeetingSerializer import MeetingSerializer
|
||||
|
||||
from core.serializers.MeetingSerializer import MeetingSerializer , MeetingSerializerFull
|
||||
from core.utils.sms import send_sms # Assuming send_sms is in core/utils/sms.py
|
||||
|
||||
from core.models.Meeting import Meeting
|
||||
|
||||
# @swagger_auto_schema(
|
||||
# method='post',
|
||||
|
@ -87,28 +89,69 @@ def addMeeting(request):
|
|||
meeting = serializer.save()
|
||||
|
||||
for user_id in user_ids:
|
||||
user = User.objects.get(id=user_id) # will raise exception if not found
|
||||
Invitation.objects.create(
|
||||
user=user,
|
||||
meeting=meeting,
|
||||
is_admin=False,
|
||||
is_sms_sent=False
|
||||
)
|
||||
try:
|
||||
user = User.objects.get(id=user_id)
|
||||
|
||||
# Create the invitation
|
||||
Invitation.objects.create(
|
||||
user=user,
|
||||
meeting=meeting,
|
||||
is_admin=False,
|
||||
is_sms_sent=True # mark true if SMS sent below
|
||||
)
|
||||
|
||||
# Send SMS to user.username (which is a phone number)
|
||||
sms_result = send_sms(to_number=user.username, code="1111")
|
||||
|
||||
print(f"SMS sent to {user.username}: {sms_result}")
|
||||
|
||||
except User.DoesNotExist:
|
||||
return Response(
|
||||
{"error": f"User with id {user_id} does not exist."},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
return Response({
|
||||
"message": "Meeting created successfully with invitations.",
|
||||
"message": "Meeting created successfully with invitations and SMS sent.",
|
||||
"meeting": serializer.data
|
||||
}, status=status.HTTP_201_CREATED)
|
||||
|
||||
except User.DoesNotExist:
|
||||
return Response(
|
||||
{"error": f"User with id {user_id} does not exist."},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
except Exception as e:
|
||||
return Response(
|
||||
{"error": str(e)},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
|
||||
|
||||
# @swagger_auto_schema(
|
||||
# method='get',
|
||||
# operation_description="Get meetings created by or invited to the authenticated user.",
|
||||
# responses={200: openapi.Response('Success', MeetingSerializer(many=True))}
|
||||
# )
|
||||
@api_view(['GET'])
|
||||
@authentication_classes([SessionAuthentication, TokenAuthentication])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def get_user_meetings(request):
|
||||
try:
|
||||
user = request.user
|
||||
|
||||
# Meetings the user created
|
||||
created_meetings = Meeting.objects.filter(creator_user=user)
|
||||
|
||||
# Meetings the user was invited to
|
||||
# invited_meetings = Meeting.objects.filter(invitation__user=user)
|
||||
invited_meetings = Meeting.objects.filter(invitations__user=user)
|
||||
|
||||
|
||||
# Combine both querysets and eliminate duplicates
|
||||
all_meetings = (created_meetings | invited_meetings).distinct()
|
||||
|
||||
serializer = MeetingSerializerFull(all_meetings, many=True)
|
||||
return Response({"meetings": serializer.data}, status=status.HTTP_200_OK)
|
||||
|
||||
except Exception as e:
|
||||
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
Loading…
Reference in New Issue
Block a user