Beispiel #1
0
def updateServiceDriver(request, id=None):
    try:
        driver_id = request.data.get('conductor')
        state = request.data.get('estado')

        driver = UserExtended.objects.get(id=driver_id)
        service = Service.objects.get(id=id)

        if service.driver is None:
            service.driver = driver
            service.state = state
            service.save()
            services_serializer = ServiceSerializer(service, many=False)
            response = {
                'content': services_serializer.data,
                'isOk': True,
                'message': '',
            }
            sendNotificationClient(services_serializer.data, service.client.id,
                                   'update')
            return Response(response, status=status.HTTP_200_OK)
        elif service.driver == driver:
            service.state = state
            service.save()
            services_serializer = ServiceSerializer(service, many=False)
            response = {
                'content': services_serializer.data,
                'isOk': True,
                'message': '',
            }
            if state == 'Servicio terminado':
                sendNotificationClient(services_serializer.data,
                                       service.client.id, 'finished')
            elif state == 'Servicio cancelado':
                sendNotificationClient(services_serializer.data,
                                       service.client.id, 'canceled')
            return Response(response, status=status.HTTP_200_OK)
        else:
            response = {
                'content': [],
                'isOk': False,
                'message': 'El servicio ya tiene un conductor asignado',
            }
            return Response(response, status=status.HTTP_200_OK)
    except Exception as e:
        response = {
            'content': [],
            'isOk': False,
            'message': str(e),
        }
        return Response(response, status=status.HTTP_200_OK)
Beispiel #2
0
def updateServiceClient(request, id=None):
    try:
        #client_id = request.data.get('cliente')
        state = request.data.get('estado')
        time = request.data.get('tiempo')
        distance = request.data.get('distancia')
        cancel_reason = request.data.get('motivo')
        update = request.data.get('actualizacion')

        #client = UserExtended.objects.get(id=client_id)
        service = Service.objects.get(id=id)
        cost = ValueKilometer.objects.all().order_by('-id')[0]
        base = BasePrice.objects.all().order_by('-id')[0]

        if update == "0":
            service.state = state
            service.cancel_reason = cancel_reason
            service.save()
            service_serializer = ServiceSerializer(service, many=False)
            sendNotificationDriver(service_serializer.data, "delete")
        elif update == "1":
            service.distance = distance
            service.time = time
            if distance > base.count_after:
                service.value = distance * cost.cost + base.base
            else:
                service.value = base.base

            service.save()
            service_serializer = ServiceSerializer(service, many=False)

        response = {
            'content': service_serializer.data,
            'isOk': True,
            'message': '',
        }
        return Response(response, status=status.HTTP_200_OK)

    except Exception as e:
        response = {
            'content': [],
            'isOk': False,
            'message': str(e),
        }
        return Response(response, status=status.HTTP_200_OK)
Beispiel #3
0
    def post(self, request, format=None):
        try:
            client_id = request.data.get('usuario')
            origin = request.data.get('origen')
            origin_lat = request.data.get('origin_lat')
            origin_lan = request.data.get('origin_lan')
            destiny = request.data.get('destino')
            destiny_lat = request.data.get('destiny_lat')
            destiny_lan = request.data.get('destiny_lan')
            type_service = request.data.get('tipo_servicio')
            disability = request.data.get('discapacidad')
            charge = request.data.get('carga')
            pet = request.data.get('mascota')
            passengers = request.data.get('pasajeros')
            description = request.data.get('descripcion')

            client = UserExtended.objects.get(id=client_id)

            service = Service.objects.create(client=client,
                                             origin_name=origin,
                                             origin_lat=origin_lat,
                                             origin_lan=origin_lan,
                                             destiny_name=destiny,
                                             destiny_lat=destiny_lat,
                                             destiny_lan=destiny_lan,
                                             type_service=type_service,
                                             disability=disability,
                                             charge=charge,
                                             pet=pet,
                                             passengers=passengers,
                                             description=description)

            service_serializers = ServiceSerializer(service, many=False)
            sendNotificationDriver(service_serializers.data, 'add')
            response = {
                'content': service_serializers.data,
                'isOk': True,
                'message': '',
            }
            return Response(response, status=status.HTTP_200_OK)

        except UserExtended.DoesNotExist:
            response = {
                'content': [],
                'isOk': False,
                'message': 'Cliente no encontrado',
            }
            return Response(response, status=status.HTTP_200_OK)
        except Exception as e:
            response = {
                'content': [],
                'isOk': False,
                'message': str(e),
            }
            return Response(response, status=status.HTTP_200_OK)
Beispiel #4
0
 def get(self, request, format=None):
     try:
         services = Service.objects.all().order_by('-date')
         services_serializer = ServiceSerializer(services, many=True)
         response = {
             'content': services_serializer.data,
             'isOk': True,
             'message': '',
         }
         return Response(response, status=status.HTTP_200_OK)
     except Exception as e:
         response = {
             'content': [],
             'isOk': False,
             'message': str(e),
         }
         return Response(response, status=status.HTTP_200_OK)
Beispiel #5
0
def getServiceWithoutDriver(request):
    try:
        services = Service.objects.filter(
            state="servicio creado").order_by('-date')
        print(services)
        services_serializer = ServiceSerializer(services, many=True)
        response = {
            'content': services_serializer.data,
            'isOk': True,
            'message': '',
        }
        return Response(response, status=status.HTTP_200_OK)
    except Exception as e:
        response = {
            'content': [],
            'isOk': False,
            'message': str(e),
        }
        return Response(response, status=status.HTTP_200_OK)
Beispiel #6
0
def getServiceDriver(request, id_driver=None):
    try:
        services_driver = Service.objects.filter(
            driver__id=id_driver).order_by('-date')
        services_driver_serializer = ServiceSerializer(services_driver,
                                                       many=True)
        response = {
            'content': services_driver_serializer.data,
            'isOk': True,
            'message': '',
        }
        return Response(response, status=status.HTTP_200_OK)
    except Exception as e:
        response = {
            'content': [],
            'isOk': False,
            'message': str(e),
        }
        return Response(response, status=status.HTTP_200_OK)