Beispiel #1
0
    def find_user_by_api_key(cls, api_key: str) -> User:

        session = DbSessionFactory.create_session()
        user = session.query(User).filter(User.api_key == api_key).first()
        session.close()

        return user
Beispiel #2
0
    def create_user(cls, username):
        session = DbSessionFactory.create_session()

        user = User(name=username)
        session.add(user)
        session.commit()
        return user
Beispiel #3
0
    def delete_car(cls, car_id):
        session = DbSessionFactory.create_session()
        db_car = session.query(Car).filter(Car.id == car_id).first()
        if not db_car:
            return

        session.delete(db_car)
        session.commit()
Beispiel #4
0
    def car_by_id(cls, car_id):
        session = DbSessionFactory.create_session()

        car = session.query(Car).filter(Car.id == car_id).first()

        session.close()

        return car
Beispiel #5
0
    def all_cars(cls, limit=None):
        session = DbSessionFactory.create_session()

        query = session.query(Car).order_by(Car.year.desc())

        if limit:
            cars = query[:limit]
        else:
            cars = query.all()

        session.close()

        return cars
Beispiel #6
0
    def update_car(cls, car):
        session = DbSessionFactory.create_session()

        db_car = session.query(Car).filter(Car.id == car.id).first()
        db_car.last_seen = car.last_seen
        db_car.brand = car.brand
        db_car.image = car.image if car.image else random.choice(
            cls.__fake_image_url)
        db_car.damage = car.damage
        db_car.year = car.year
        db_car.price = car.price
        db_car.name = car.name

        session.commit()

        return db_car
Beispiel #7
0
    def add_car(cls, car: Car):
        session = DbSessionFactory.create_session()

        db_car = Car()
        db_car.last_seen = parse(car.last_seen)
        db_car.brand = car.brand
        db_car.image = car.image if car.image else random.choice(
            cls.__fake_image_url)
        db_car.damage = car.damage
        db_car.year = int(car.year)
        db_car.price = int(car.price)
        db_car.name = car.name

        session.add(db_car)
        session.commit()

        return db_car