Esempio n. 1
0
def user_create_room(request):
    try:
        post_data = json.loads(request.body)
        user_id = post_data['user_id']
        nickname = post_data['nickname'] #redundant but needed
        room_name = post_data['room_name']
        room_description = post_data['room_description']
        company_id = post_data['company_id'] 
        
        company = Company.objects(company_id=company_id).first()
        company_id = company.id
    
        chatRoom = ChatRoom(owner=user_id, name=room_name, description=room_description, company=company_id, nickname=nickname)
        chatRoom.save()
        serializer = ChatroomSerializer(chatRoom, many=False) 
        chatUser = ChatUser(user=user_id, room=chatRoom.id, company=company_id, nickname=nickname)
        chatUser.save()
        return JsonResponse({"message": "Channel created and you have joined it", "room" : serializer.data}, safe=False)
    except Exception as e:
        return JsonResponse({'Error' : str(e)})