Esempio n. 1
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('name',
                            type=str,
                            required=True,
                            help="Name cannot be left blank")
        parser.add_argument('subname',
                            type=str,
                            required=True,
                            help="Subname cannot be left blank")
        parser.add_argument('dni',
                            type=str,
                            required=True,
                            help="DNI cannot be left blank")
        parser.add_argument('password',
                            type=str,
                            required=True,
                            help="Password cannot be left blank")
        parser.add_argument('date_registration',
                            type=str,
                            required=True,
                            help="Date Registration cannot be left blank")
        data = parser.parse_args()

        try:
            mechanic = MechanicModel(data['name'], data['subname'],
                                     data['dni'], data['password'],
                                     data['date_registration'])
            MechanicModel.save_to_db(mechanic)
            return {"message": "Mechanic added successfully"}, 200
        except:
            return {"message": "Error Post Mechanic"}, 500
Esempio n. 2
0
 def delete(self, id):
     try:
         mechanic = MechanicModel.find_by_id(id)
         if mechanic:
             MechanicModel.delete_from_db(mechanic)
             return {"message": "Mechanic deleted"}, 200
         return {"message": "Mechanic not found "}, 404
     except:
         return {"message": "Error Delete Mechanic"}, 500
Esempio n. 3
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('email',
                            type=str,
                            required=True,
                            help="Email cannot be left blank")
        parser.add_argument('password',
                            type=str,
                            required=True,
                            help="Password cannot be left blank")
        data = parser.parse_args()

        try:
            email_aux = data['email'].split("@")
            #print(email_aux)
            if "mooving.com" in email_aux:
                #print("entramos mecanico")
                mechanic = MechanicModel.find_by_email(data['email'])
                if mechanic:
                    if mechanic.verify_password(data['password']):
                        return {
                            'message': "Login succesfull",
                            'mechanic': mechanic.json(),
                            'type': "mechanic"
                        }, 200
                    else:
                        return {"message": "Wrong password"}, 400
                else:
                    return {"message": "Mechanic not found"}, 404

            else:
                #print("entramos cliente")
                client = ClientModel.find_by_email(data['email'])
                if client:
                    if client.verify_password(data['password']):
                        return {
                            'message': "Login succesfull",
                            'client': client.json(),
                            'type': "client"
                        }, 200
                    else:
                        return {"message": "Wrong password"}, 400
                else:
                    return {"message": "User not found"}, 404
        except:
            return {"message": "Error Post Login"}, 500
Esempio n. 4
0
    def put(self, id):
        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, required=False)
        parser.add_argument('subname', type=str, required=False)
        parser.add_argument('password', type=str, required=False)
        data = parser.parse_args()

        try:
            mechanic = MechanicModel.find_by_id(id)
            if data['name']:
                mechanic.set_name(data['name'])
            if data['subname']:
                mechanic.set_subname(data['subname'])
            if data['password']:
                mechanic.set_password(data['password'])

            return {"message": "Mechanic modified successfully"}, 200
        except:
            return {"message": "Error Put Mechanic"}, 500
Esempio n. 5
0
def init_db():
    db.drop_all()
    db.create_all()
    new_moto1 = MotoModel(state="AVAILABLE",
                          matricula="1111-MMM",
                          date_estreno="28/10/2020",
                          model_generic="basic",
                          last_coordinate_latitude=41.403193,
                          last_coordinate_longitude=2.175004,
                          km_restantes=34.0,
                          km_totales=300.0,
                          date_last_check="18/10/2020",
                          km_last_check=0.0)
    db.session.add(new_moto1)

    new_moto2 = MotoModel(state="AVAILABLE",
                          matricula="2222-MMM",
                          date_estreno="28/10/2020",
                          model_generic="basic",
                          last_coordinate_latitude=41.403719,
                          last_coordinate_longitude=2.189128,
                          km_restantes=3.0,
                          km_totales=23.0,
                          date_last_check="18/10/2020",
                          km_last_check=0.0)
    db.session.add(new_moto2)

    new_moto3 = MotoModel(state="AVAILABLE",
                          matricula="3333-MMM",
                          date_estreno="28/10/2020",
                          model_generic="premium",
                          last_coordinate_latitude=41.386399,
                          last_coordinate_longitude=2.164143,
                          km_restantes=120.0,
                          km_totales=500.0,
                          date_last_check="18/10/2020",
                          km_last_check=0.0)
    db.session.add(new_moto3)

    new_moto = MotoModel(state="AVAILABLE",
                         matricula="4444-MMM",
                         date_estreno="28/10/2020",
                         model_generic="premium",
                         last_coordinate_latitude=41.348788,
                         last_coordinate_longitude=2.132925,
                         km_restantes=45.0,
                         km_totales=203.0,
                         date_last_check="18/10/2020",
                         km_last_check=0.0)
    db.session.add(new_moto)

    new_moto = MotoModel(state="LOW_BATTERY_FUEL",
                         matricula="5555-MMM",
                         date_estreno="08/10/2020",
                         model_generic="premium",
                         last_coordinate_latitude=41.413273,
                         last_coordinate_longitude=2.152931,
                         km_restantes=2.0,
                         km_totales=100.0,
                         date_last_check="18/10/2020",
                         km_last_check=100.0)
    db.session.add(new_moto)

    new_moto = MotoModel(state="LOW_BATTERY_FUEL",
                         matricula="6666-MMM",
                         date_estreno="08/10/2020",
                         model_generic="premium",
                         last_coordinate_latitude=41.427691,
                         last_coordinate_longitude=2.166293,
                         km_restantes=4.0,
                         km_totales=100.0,
                         date_last_check="18/10/2020",
                         km_last_check=100.0)
    db.session.add(new_moto)

    new_moto = MotoModel(state="AVAILABLE",
                         matricula="7777-MMM",
                         date_estreno="28/10/2020",
                         model_generic="premium",
                         last_coordinate_latitude=41.387818,
                         last_coordinate_longitude=2.169647,
                         km_restantes=23.0,
                         km_totales=203.0,
                         date_last_check="18/10/2020",
                         km_last_check=0.0)
    db.session.add(new_moto)

    new_moto = MotoModel(state="AVAILABLE",
                         matricula="8888-MMM",
                         date_estreno="28/10/2020",
                         model_generic="basic",
                         last_coordinate_latitude=41.375960,
                         last_coordinate_longitude=2.177455,
                         km_restantes=35.0,
                         km_totales=203.0,
                         date_last_check="18/10/2020",
                         km_last_check=100.0)
    db.session.add(new_moto)

    new_moto = MotoModel(state="AVAILABLE",
                         matricula="5454-MMM",
                         date_estreno="28/11/2020",
                         model_generic="premium",
                         last_coordinate_latitude=41.384223,
                         last_coordinate_longitude=2.160337,
                         km_restantes=35.0,
                         km_totales=403.0,
                         date_last_check="28/10/2020",
                         km_last_check=100.0)
    db.session.add(new_moto)

    new_moto = MotoModel(state="AVAILABLE",
                         matricula="4545-MMM",
                         date_estreno="28/11/2020",
                         model_generic="premium",
                         last_coordinate_latitude=41.359768,
                         last_coordinate_longitude=2.084035,
                         km_restantes=35.0,
                         km_totales=403.0,
                         date_last_check="28/10/2020",
                         km_last_check=100.0)
    db.session.add(new_moto)

    new_moto9 = MotoModel(state="AVAILABLE",
                          matricula="9999-MMM",
                          date_estreno="28/10/2020",
                          model_generic="basic",
                          last_coordinate_latitude=41.591158,
                          last_coordinate_longitude=1.520865,
                          km_restantes=34.0,
                          km_totales=300.0,
                          date_last_check="18/10/2020",
                          km_last_check=0.0)
    db.session.add(new_moto9)

    new_moto10 = MotoModel(state="AVAILABLE",
                           matricula="1010-MMM",
                           date_estreno="28/10/2020",
                           model_generic="basic",
                           last_coordinate_latitude=41.591158,
                           last_coordinate_longitude=1.5209,
                           km_restantes=999.0,
                           km_totales=300.0,
                           date_last_check="18/10/2020",
                           km_last_check=0.0)
    db.session.add(new_moto10)

    client1 = ClientModel(nombre="Juana",
                          iban="2223462362665251w",
                          dni_nie="11111111J",
                          email="*****@*****.**",
                          password="******")
    db.session.add(client1)

    client2 = ClientModel(nombre="Camila",
                          iban="22462362665251w",
                          dni_nie="14441111J",
                          email="*****@*****.**",
                          password="******")
    db.session.add(client2)

    client3 = ClientModel(nombre="Sofia",
                          iban="2223332362665251w",
                          dni_nie="11188881J",
                          email="*****@*****.**",
                          password="******")
    db.session.add(client3)

    client = ClientModel(nombre="Ramona",
                         iban="225554362665251w",
                         dni_nie="12341111J",
                         email="*****@*****.**",
                         password="******")
    db.session.add(client)

    articulo = ArticleModel(
        titulo="¡Motos más nuevas y potentes que nunca!",
        texto="Las nuevas motos de Mooving están batiendo todos los"
        "récord habidos y por haber. Tenemos más de 400 motos eléctricas"
        "con una autonomía de más de 100KM.",
        fecha_creacion="2020/10/29",
        visible=True)
    db.session.add(articulo)

    articulo = ArticleModel(
        titulo="¡Motos más rápidas !",
        texto=
        "Las nuevas motos de Mooving son más rápidas que las de la competencia."
        " Tenemos más de 400 motos eléctricas"
        " con una velocidad punta de más de 100KM/H .",
        fecha_creacion="2020/10/28",
        visible=True)
    db.session.add(articulo)

    new_mechanic = MechanicModel(name="Jose",
                                 subname="De carglass",
                                 dni="11111111J",
                                 password="******",
                                 date_registration="23/02/2020")
    db.session.add(new_mechanic)

    new_mechanic = MechanicModel(name="Pepe",
                                 subname="De marcota",
                                 dni="22222222J",
                                 password="******",
                                 date_registration="24/02/2020")
    db.session.add(new_mechanic)

    db.session.commit()
    print('Success in adding items to database')
Esempio n. 6
0
 def get(self):
     data = {'mechanics': []}
     mechanics = MechanicModel.get_all()
     for m in mechanics:
         data['mechanics'].append(m.json())
     return data
Esempio n. 7
0
 def get(self, id):
     try:
         mechanic = MechanicModel.find_by_id(id)
         return {'mechanic': mechanic.json()}, 200
     except:
         return {"message": "Error Get Mechanic"}, 500
Esempio n. 8
0
def add_data(db=db):

    new_moto1 = MotoModel(
        state="AVAILABLE",
        matricula="1111-MMM",
        date_estreno="28/10/2020",
        model_generic="basic",
        last_coordinate_latitude=41.40181444604073,
        last_coordinate_longitude=2.1602937877348554,
        km_restantes=80.0,
        km_totales=300.0,
        date_last_check="18/10/2020",
        km_last_check=0.0)
    db.session.add(new_moto1)

    new_moto2 = MotoModel(
        state="AVAILABLE",
        matricula="2222-MMM",
        date_estreno="28/10/2020",
        model_generic="basic",
        last_coordinate_latitude=41.40514485607213,
        last_coordinate_longitude=2.1587408287276393,
        km_restantes=80.0,
        km_totales=23.0,
        date_last_check="18/10/2020",
        km_last_check=0.0)
    db.session.add(new_moto2)

    new_moto3 = MotoModel(
        state="AVAILABLE",
        matricula="3333-MMM",
        date_estreno="28/10/2020",
        model_generic="premium",
        last_coordinate_latitude=41.40396129395845,
        last_coordinate_longitude=2.1672429122257184,
        km_restantes=120.0,
        km_totales=500.0,
        date_last_check="18/10/2020",
        km_last_check=0.0)
    db.session.add(new_moto3)

    new_moto = MotoModel(
        state="AVAILABLE",
        matricula="4444-MMM",
        date_estreno="28/10/2020",
        model_generic="premium",
        last_coordinate_latitude=41.403205972568855,
        last_coordinate_longitude=2.155472976562771,
        km_restantes=120.0,
        km_totales=203.0,
        date_last_check="18/10/2020",
        km_last_check=0.0)
    db.session.add(new_moto)

    new_moto = MotoModel(
        state="LOW_BATTERY_FUEL",
        matricula="5555-MMM",
        date_estreno="08/10/2020",
        model_generic="premium",
        last_coordinate_latitude=41.40510495456656,
        last_coordinate_longitude=2.166668308564227,
        km_restantes=30.0,
        km_totales=100.0,
        date_last_check="18/10/2020",
        km_last_check=100.0)
    db.session.add(new_moto)

    new_moto = MotoModel(
        state="LOW_BATTERY_FUEL",
        matricula="6666-MMM",
        date_estreno="08/10/2020",
        model_generic="premium",
        last_coordinate_latitude=41.40551322372631,
        last_coordinate_longitude=2.163830433113226 ,
        km_restantes=30.0,
        km_totales=100.0,
        date_last_check="18/10/2020",
        km_last_check=100.0)
    db.session.add(new_moto)

    client1 = ClientModel(
        nombre="Juana",
        iban="2223462362665251w",
        dni_nie="11111111J",
        email="*****@*****.**",
        password="******"
    )
    db.session.add(client1)

    client2 = ClientModel(
        nombre="Camila",
        iban="22462362665251w",
        dni_nie="14441111J",
        email="*****@*****.**",
        password="******"

    )
    db.session.add(client2)

    client3 = ClientModel(
        nombre="Sofia",
        iban="2223332362665251w",
        dni_nie="11188881J",
        email="*****@*****.**",
        password="******"
    )
    db.session.add(client3)

    client = ClientModel(
        nombre="Ramona",
        iban="225554362665251w",
        dni_nie="12341111J",
        email="*****@*****.**",
        password="******"
    )
    db.session.add(client)

    articulo = ArticleModel(
        titulo="¡Motos más nuevas y potentes que nunca!",
        texto="Las nuevas motos de Mooving están batiendo todos los"
              "récord habidos y por haber. Tenemos más de 400 motos eléctricas"
              "con una autonomía de más de 100KM.",
        fecha_creacion="2020/10/29",
        visible=True)
    db.session.add(articulo)

    articulo = ArticleModel(
        titulo="¡Motos más rápidas !",
        texto="Las nuevas motos de Mooving son más rápidas que las de la competencia."
              " Tenemos más de 400 motos eléctricas"
              " con una velocidad punta de más de 100KM/H .",
        fecha_creacion="2020/10/28",
        visible=True)
    db.session.add(articulo)

    new_mechanic = MechanicModel(
        name="Jose",
        subname="De carglass",
        dni="11111111J",
        password="******",
        date_registration="23/02/2020")
    db.session.add(new_mechanic)

    new_mechanic = MechanicModel(
        name="Pepe",
        subname="De marcota",
        dni="22222222J",
        password="******",
        date_registration="24/02/2020")
    db.session.add(new_mechanic)

    db.session.commit()
    print('Success in adding items to database')