def post(payload: Payload): try: if REDIS.get(f"{payload.name}"): raise Exception(f"Fruit {payload.name} already exists!") Fruit(**{"name": payload.name, "count": payload.count}).add() Fruit.commit() REDIS.set(f"{payload.name}", f"{payload.count}") return EnumResponse.OK.value.response except Exception as error: logger.warning(error) return EnumResponse.BAD_REQUEST.value.response
def clean_db(): Fruit.query().delete() Fruit.commit()
def init_db(): Fruit(**{"name": "apple", "count": 1}).add() Fruit.commit()