from rest_framework import status from django.http import Http404 from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.serializers import ValidationError from api.queue_datastructure import Queue from api.mensajes import send_message import json queueF = Queue('FIFO') queueL = Queue('LIFO') """ The MembersView will contain the logic on how to: GET, POST, PUT or delete family members """ class QueueView(APIView): def get(self, request): next = queueF.dequeue() result = str(next) + " , eres el siguiente en la lista" mynumber= "+56968422617" send_message(mynumber, result) return Response(json.dumps(result), status=status.HTTP_200_OK) def post(self, request): espera = queueF.size() - 2 queueF.enqueue(json.loads(request.body)['name'])
from rest_framework import status from django.http import Http404 from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.serializers import ValidationError from api.queue_datastructure import Queue from api.queue_datastructure import Twilio import json # initialize a 'Doe' family queue = Queue(mode='FIFO') twilio = Twilio() """ The MembersView will contain the logic on how to: GET, POST, PUT or delete family members """ class QueueView(APIView): def get(self, request): result = queue.dequeue() return Response(result, status=status.HTTP_200_OK) def post(self, request): # add a new member to the queue item = request.data result = queue.enqueue(item) return Response(result, status=status.HTTP_200_OK)
from rest_framework import status from django.http import Http404 from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.serializers import ValidationError from api.queue_datastructure import Queue import json # initialize a 'Doe' family queue = Queue('FIFO') """ The MembersView will contain the logic on how to: GET, POST, PUT or delete family members """ class QueueView(APIView): def get(self, request): # fill this method and update the return if queue.size() != 0: queue.dequeue() return Response("Turn was assigned", status=status.HTTP_200_OK) else: return Response("The list is empty, no need to dequeue", status=status.HTTP_200_OK) def post(self, request): # add a new member to the queue if request is not None: queue.enqueue(request) return Response(status=status.HTTP_200_OK)
from rest_framework import status from django.http import Http404 from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.serializers import ValidationError from api.queue_datastructure import Queue from api.message import sendMessage import json # initialize a 'Doe' family queue = Queue(mode='FIFO') queue2 = Queue(mode='LIFO') """ The MembersView will contain the logic on how to: GET, POST, PUT or delete family members """ class QueueView(APIView): def get(self, request): result = queue.dequeue() sendMessage('Su turno') return Response(json.dumps(result), status=status.HTTP_200_OK) def post(self, request): val = json.loads(request.body) queue.enqueue(val) sendMessage('Su número es el' + str(queue.size())) return Response(json.dumps("ok"), status=status.HTTP_200_OK)