Merge branch 'develop/backend-api-dispositivo' into 'develop/backend'
Develop/backend api dispositivo See merge request m3f_usm/T_digital_Transporte_USM!3develop/backend-letrero
commit
4567b795f2
|
@ -9,6 +9,11 @@ class AplicacionSerializer(serializers.ModelSerializer):
|
|||
model = models.Aplicacion
|
||||
fields = '__all__'
|
||||
|
||||
class DispositivoSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = models.Dispositivo
|
||||
fields = '__all__'
|
||||
|
||||
class TipoDispositivoSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = models.TipoDispositivo
|
||||
|
|
|
@ -4,11 +4,13 @@ from rest_framework import routers
|
|||
from api.views import usuario, auth, aplicacion, tipo, persona, comuna, region, paradero, rol, rolaplicacion
|
||||
from api.views import mapa, linea, operador
|
||||
from api.views import paradero_imagen
|
||||
from api.views import dispositivo
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register('aplicaciones', aplicacion.AplicacionViewSet)
|
||||
router.register('usuarios', usuario.UsuarioViewSet)
|
||||
router.register('personas', persona.PersonaViewSet)
|
||||
router.register('dispositivos', dispositivo.DispositivoViewSet)
|
||||
router.register('tipos/persona', tipo.TipoTratamientoPersonaViewSet)
|
||||
router.register('tipos/transporte', tipo.TipoTransporteViewSet)
|
||||
router.register('tipos/dispositivo', tipo.TipoDispositivoViewSet)
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
|
||||
from rest_framework import viewsets
|
||||
from django.http import JsonResponse
|
||||
from rest_framework.decorators import action
|
||||
from .. import models, serializers
|
||||
import json
|
||||
|
||||
class DispositivoViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.Dispositivo.objects.all()
|
||||
serializer_class = serializers.DispositivoSerializer
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def whoami(self, request, pk=None):
|
||||
input = json.loads(request.body)
|
||||
whoami = input['whoami']
|
||||
|
||||
if (whoami['idDispositivo'] == 'existe'):
|
||||
return JsonResponse({
|
||||
"WhoamiResponse": {
|
||||
"NroParadero": "AAA330",
|
||||
"NombreParadero":"paradero 1 esq colon",
|
||||
"Status": "OK"
|
||||
}
|
||||
})
|
||||
|
||||
# retorna json de no existente
|
||||
return JsonResponse({
|
||||
"WhoamiResponse": {
|
||||
"Status": "NOK",
|
||||
"errorString": "Dispositivo no identificado"
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def getInfoDevice(self, request, pk=None):
|
||||
input = json.loads(request.body)
|
||||
|
||||
linea1 = {
|
||||
"Linea": "803010",
|
||||
"Descripcion": "Tucapel",
|
||||
"TipoLocomocion": 1,
|
||||
"colorFondo": "Hexadecimal",
|
||||
"colorLetra": "Hexadecimal",
|
||||
"Llegadas": [
|
||||
{
|
||||
"Patente": "RPDA-98",
|
||||
"Planificada": "",
|
||||
"EstimadaGPS": "15:08",
|
||||
"DistanciaGPS": "1.0 KM"
|
||||
},
|
||||
{
|
||||
"Patente": "WYXYZ-22",
|
||||
"Planificada": "",
|
||||
"EstimadaGPS": "15:42",
|
||||
"DistanciaGPS": "5.0 KM"
|
||||
},
|
||||
{
|
||||
"Patente": "ABCA-65",
|
||||
"Planificada": "",
|
||||
"EstimadaGPS": "16:18",
|
||||
"DistanciaGPS": "13.4 KM"
|
||||
}
|
||||
],
|
||||
"Mensajelinea": ""
|
||||
}
|
||||
|
||||
linea2 = {
|
||||
"Linea": "5487",
|
||||
"Descripcion": "Centauro",
|
||||
"TipoLocomocion": 1,
|
||||
"colorFondo": "Hexadecimal",
|
||||
"colorLetra": "Hexadecimal",
|
||||
"Llegadas": [
|
||||
{
|
||||
"Patente": "PLKJ-32",
|
||||
"Planificada": "15:13",
|
||||
"EstimadaGPS": "",
|
||||
"DistanciaGPS": "",
|
||||
},
|
||||
{
|
||||
"Patente": "GHLK-11",
|
||||
"Planificada": "15:39",
|
||||
"EstimadaGPS": "",
|
||||
"DistanciaGPS": "",
|
||||
},
|
||||
{
|
||||
"Patente": "DFQW-55",
|
||||
"Planificada": "16:22",
|
||||
"EstimadaGPS": "",
|
||||
"DistanciaGPS": "",
|
||||
}
|
||||
],
|
||||
"Mensajelinea": "Sin info. GPS, la informacion es estimada"
|
||||
}
|
||||
|
||||
detalle_lineas = []
|
||||
detalle_lineas.append(linea1)
|
||||
detalle_lineas.append(linea2)
|
||||
|
||||
return JsonResponse({
|
||||
"GetInfoDeviceResponse": {
|
||||
"DetalleLineas": detalle_lineas,
|
||||
"MensajeParadero": "No considerar, uso futuro"
|
||||
}
|
||||
})
|
|
@ -0,0 +1,63 @@
|
|||
|
||||
@server = http://localhost:4000/api
|
||||
@token = {{login.response.body.$.token}}
|
||||
|
||||
###
|
||||
# @name login
|
||||
POST {{server}}/auth/
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "0",
|
||||
"password": "0"
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# @name list
|
||||
GET {{server}}/dispositivos
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
###
|
||||
# @name whoami_existente
|
||||
POST {{server}}/dispositivos/whoami/
|
||||
Authorization: Bearer {{token}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"whoami": {
|
||||
"idDispositivo": "existe",
|
||||
"KeyAutorizacion": "token"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# @name whoami_no_existe
|
||||
POST {{server}}/dispositivos/whoami/
|
||||
Authorization: Bearer {{token}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"whoami": {
|
||||
"idDispositivo": "otro",
|
||||
"KeyAutorizacion": "token"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# @name get_info_device
|
||||
POST {{server}}/dispositivos/getInfoDevice/
|
||||
Authorization: Bearer {{token}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"GetInfoDevice": {
|
||||
"idDispositivo": "existe",
|
||||
"KeyAutorizacion":"token"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
###
|
Loading…
Reference in New Issue