| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import pathlib
- current = pathlib.Path(__file__).parent
- root = current.parent
- import sys
- sys.path.append(str(root))
- import assets
- import sqlmodel
- def drop_database() -> None:
- db = pathlib.Path("./009-reservation.db")
- if db.is_file():
- db.unlink()
- drop_database()
- connection = sqlmodel.create_engine("sqlite:///009-reservation.db")
- sqlmodel.SQLModel.metadata.create_all(connection)
- builder = assets.product_factory()
- builder.name = "Sample name"
- builder.author = "Simple UwU Artist"
- builder.description = "This is simple description"
- builder.barcode = "123456789012"
- builder.stock_count = 10
- product = builder.result
- print("Create first product:")
- print(product)
- print()
- with assets.product_loader(connection) as loader:
- print("Inserting product...")
- loader.store(product)
- print("Inserted:")
- print(product)
- print()
- with assets.product_loader(connection) as loader:
- print("Loading product to make reservation...")
- target = loader.get_by_barcode("123456789012")
- print("Loaded: ")
- print(target)
- before = target.on_stock
- reservation = assets \
- .reservation_factory() \
- .target(target) \
- .email("[email protected]") \
- .result()
- print(reservation)
- print()
- with assets.reservation_loader(connection) as loader:
- print("Inserting it into database...")
- loader.store(reservation)
- print(reservation)
- with assets.product_loader(connection) as loader:
- print("Loading product to make reservation...")
- target = loader.get_by_barcode("123456789012")
- print("Loaded: ")
- print(target)
- reservation = assets \
- .reservation_factory() \
- .target(target) \
- .email("[email protected]") \
- .result()
- print(reservation)
- print()
- with assets.reservation_loader(connection) as loader:
- print("Inserting it into database...")
- loader.store(reservation)
- print(reservation)
- users = assets.users_collection()
- factory = assets.user_factory()
- factory.nick = "test"
- factory.password = "12345678"
- users.add(factory.result)
- app = assets.reservation_app(connection, users)
- print("App initialized.")
- print()
- print("Loading all reservations:")
- print(app.get_by_product({
- "apikey": factory.apikey,
- "target_barcode": "123456789012",
- }))
- print(app.get_by_user({
- "apikey": factory.apikey,
- "email": "[email protected]"
- }))
- print()
- print("Giving back item:")
- print(app.give_back_product({
- "apikey": factory.apikey,
- "target_barcode": "123456789012",
- "email": "[email protected]"
- }))
- print("After:")
- print(app.get_by_product({
- "apikey": factory.apikey,
- "target_barcode": "123456789012",
- }))
- print()
- print("Rent product:")
- print(app.rent_product({
- "apikey": factory.apikey,
- "target_barcode": "123456789012",
- "email": "[email protected]"
- }))
- print(app.rent_product({
- "apikey": factory.apikey,
- "target_barcode": "123456789012",
- "email": "[email protected]",
- "phone_number": "+48 123456789"
- }))
- print("After:")
- print(app.get_by_product({
- "apikey": factory.apikey,
- "target_barcode": "123456789012",
- }))
- print()
- drop_database()
|