コード例 #1
0
    def create(self, **kwargs):
        """Create a repair.

        **kwargs:
        vehicle_id: vehicle id
        mileage: mileage vehicle
        client_observations: observation from clients
        mechanical_observations: observations from mechanical
        final_observations: observations post reparation
        date_entry:
        date_exit:
        price:
        status: "EN TALLER", "FINALIZADO".
        """
        kwargs = convert_uppercase(param=kwargs)
        CheckRepairDataFormat(kwargs)
        columns = ",".join([*kwargs.keys()])
        values = list(kwargs.values())
        placeholders = ','.join(['?'] * len(kwargs))
        try:
            self.sql = f"INSERT INTO REPAIRS({columns}) VALUES({placeholders})"
            self.cursor.execute(self.sql, values)
            self.connection.commit()
        except Exception:
            raise RepairCreateException()
コード例 #2
0
    def update(self, repair_id: int, **kwargs):
        """Update repair details.

        **kwargs:
        vehicle_id: vehicle id
        mileage: mileage vehicle
        client_observations: observation from clients
        mechanical_observations: observations from mechanical
        final_observations: observations post reparation
        date_entry:
        date_exit:
        price:
        status: "EN TALLER", "FINALIZADO".
        """
        kwargs = convert_uppercase(param=kwargs)
        CheckRepairDataFormat(kwargs)
        values = list(kwargs.values())
        values.append(repair_id)
        columns = list(kwargs.keys())
        columns = [column + " = ?" for column in columns]
        columns = " , ".join(columns)
        try:
            self.sql = f"UPDATE REPAIRS SET {columns} WHERE repair_id = ?"
            self.cursor.execute(self.sql, (values))
            self.connection.commit()
        except Exception:
            raise RepairUpdateException()
コード例 #3
0
    def update(self, **kwargs):
        """Update client details

        **kwargs:
        id: client id
        name: client name
        last_name: client last name
        identity_card: client identity card
        email: client email
        phone_1: client phone 1
        phone_2: client phone 2
        address: client address.
        """
        try:
            CheckClientDataFormat(client_data=kwargs)
        except ClientFormatDataException as error:
            raise ClientFormatDataException(message=error.message)
        kwargs = convert_uppercase(param=kwargs)
        values = list(kwargs.values())
        values.append(kwargs.get("client_id"))
        columns = list(kwargs.keys())
        columns = [column + " = ?" for column in columns]
        columns = " , ".join(columns)
        try:
            self.sql = f"UPDATE CLIENTS SET {columns} WHERE client_id = ?"
            self.cursor.execute(self.sql, values)
            self.connection.commit()
        except sqlite3.IntegrityError:
            raise sqlite3.IntegrityError()
        except Exception:
            raise ClientUpdateException()
コード例 #4
0
    def create(self, **kwargs):
        """Create a client

         **kwargs:
        name: client name
        last_name: client last name
        identity_card: client identity card
        email: client email
        phone_1: client phone 1
        phone_2: client phone 2
        address: client address.
        """

        try:
            CheckClientDataFormat(client_data=kwargs)
        except ClientFormatDataException as error:
            raise ClientFormatDataException(message=error.message)
        kwargs = convert_uppercase(param=kwargs)
        columns = ",".join([*kwargs.keys()])
        values = list(kwargs.values())
        placeholders = ','.join(['?'] * len(kwargs))
        try:
            self.sql = f"INSERT INTO CLIENTS({columns}) VALUES({placeholders})"
            self.cursor.execute(self.sql, values)
            self.connection.commit()
        except sqlite3.IntegrityError:
            raise sqlite3.IntegrityError()
        except Exception:
            raise ClientCreateException()
コード例 #5
0
    def create(self, **kwargs):
        """Create a vehicle type

         **kwargs:
        brand: vehicle brand
        model: vehicle model
        year: vehicle year.
        """

        kwargs = convert_uppercase(param=kwargs)
        try:
            CheckVehicleTypeDataFormat(vehicle_type_data=kwargs)
        except VehicleTypeFormatDataException as error:
            raise VehicleTypeFormatDataException(message=error.message)
        # Check if the vehicle type already exists
        vehicle_type_id = self.get_vehicle_type_id(brand=kwargs["brand"],
                                                   model=kwargs["model"],
                                                   year=int(kwargs["year"]))
        if vehicle_type_id:
            raise VehicleTypeAlreadyExistsException()
        columns = ",".join([*kwargs.keys()])
        values = list(kwargs.values())
        placeholders = ','.join(['?'] * len(kwargs))
        try:
            self.sql = f"INSERT INTO VEHICLES_TYPE({columns}) VALUES({placeholders})"
            self.cursor.execute(self.sql, values)
            self.connection.commit()
        except Exception:
            raise VehicleTypeCreateException()
コード例 #6
0
    def update(self, vehicle_type_id: int, **kwargs):
        """Update vehicle type details.

         **kwargs:
        brand: vehicle brand
        model: vehicle model
        year: vehicle year.
        """

        kwargs = convert_uppercase(param=kwargs)
        try:
            CheckVehicleTypeDataFormat(vehicle_type_data=kwargs)
        except VehicleTypeFormatDataException as error:
            raise VehicleTypeFormatDataException(message=error.message)
        # Check if the vehicle type already exists
        vehicle_type_id = self.get_vehicle_type_id(brand=kwargs["brand"],
                                                   model=kwargs["model"],
                                                   year=int(kwargs["year"]))
        if vehicle_type_id:
            raise VehicleTypeAlreadyExistsException()
        values = list(kwargs.values())
        values.append(vehicle_type_id)
        columns = list(kwargs.keys())
        columns = [column + " = ?" for column in columns]
        columns = " , ".join(columns)
        try:
            self.sql = f"UPDATE VEHICLES_TYPE SET {columns} WHERE vehicle_type_id = ?"
            self.cursor.execute(self.sql, values)
            self.connection.commit()
        except Exception:
            raise VehicleTypeUpdateException()
コード例 #7
0
 def get_by_email(self, email: str):
     """Get a client by email."""
     email = convert_uppercase(param=email)
     try:
         self.sql = "SELECT * FROM CLIENTS WHERE email=?"
         values = self.cursor.execute(self.sql, (email, ))
     except Exception:
         raise ClientGetCategoryException()
     columns = list(map(lambda x: x[0], self.cursor.description))
     clients = [dict(zip(columns, value)) for value in values]
     return clients
コード例 #8
0
 def get_by_identity_card(self, identity_card: str):
     """Get a client by identity card."""
     identity_card = convert_uppercase(param=identity_card)
     try:
         self.sql = "SELECT * FROM CLIENTS WHERE identity_card=?"
         values = self.cursor.execute(self.sql, (identity_card, ))
     except Exception:
         raise ClientGetCategoryException()
     columns = list(map(lambda x: x[0], self.cursor.description))
     clients = [dict(zip(columns, value)) for value in values]
     return clients
コード例 #9
0
 def get_by_last_name(self, last_name: str):
     """Get a client by last name."""
     last_name = convert_uppercase(param=last_name)
     try:
         self.sql = "SELECT * FROM CLIENTS WHERE last_name=?"
         values = self.cursor.execute(self.sql, (last_name, ))
     except Exception:
         raise ClientGetCategoryException()
     columns = list(map(lambda x: x[0], self.cursor.description))
     clients = [dict(zip(columns, value)) for value in values]
     return clients
コード例 #10
0
    def create(self, **kwargs):
        """Create a vehicle.

        **kwargs:
        vehicle_type_id: Vehicle type ID
        identity": Identity of the vehicle
        color: Vehicle color
        """
        kwargs = convert_uppercase(param=kwargs)
        CheckVehicleDataFormat(kwargs)
        columns = ",".join([*kwargs.keys()])
        values = list(kwargs.values())
        placeholders = ','.join(['?'] * len(kwargs))
        try:
            self.sql = f"INSERT INTO VEHICLES({columns}) VALUES({placeholders})"
            self.cursor.execute(self.sql, values)
            self.connection.commit()
        except sqlite3.IntegrityError:
            raise sqlite3.IntegrityError()
        except Exception:
            raise VehicleCreateException()
コード例 #11
0
    def update(self, vehicle_id: int, **kwargs):
        """Update client details

        **kwargs:
        vehicle_type_id: Vehicle type ID
        identity": Identity of the vehicle
        color: Vehicle color
        """
        kwargs = convert_uppercase(param=kwargs)
        CheckVehicleDataFormat(kwargs)
        values = list(kwargs.values())
        values.append(vehicle_id)
        columns = list(kwargs.keys())
        columns = [column + " = ?" for column in columns]
        columns = " , ".join(columns)
        try:
            self.sql = f"UPDATE VEHICLES SET {columns} WHERE vehicle_id = ?"
            self.cursor.execute(self.sql, (values))
            self.connection.commit()
        except sqlite3.IntegrityError:
            raise sqlite3.IntegrityError()
        except Exception:
            raise VehicleUpdateException()