]> apps.delaporte.us Git - matrix-shop-bot.git/commitdiff
Add missing functions
authorEdward Delaporte <edward@delaporte.us>
Sun, 29 Mar 2026 15:54:31 +0000 (10:54 -0500)
committerEdward Delaporte <edward@delaporte.us>
Sun, 29 Mar 2026 15:54:31 +0000 (10:54 -0500)
matrix_shop_bot/db.py
matrix_shop_bot/tasks.py

index 407a12a733633fcc82e6f02269fbd69ece961615..0d1f5902e7b08ec21addb94c6adefa2e9fb20041 100644 (file)
@@ -94,16 +94,21 @@ class Data():
     def clear_list(self, store_id, clear_all=False):
         with Session(self.engine) as session:
             store = session.exec(_get_with_id(Store, store_id)).first()
-            for item in store.items:
-                if clear_all or item.purchased_date:
-                    item.remove()
+            for item in store.shopping_list:
+                if clear_all or item.purchase_date:
+                    session.delete(item)
             session.commit()
 
+    def get_stores(self):
+        with Session(self.engine) as session:
+            cmd = select(Store)
+            return session.exec(cmd).all()
+
     def get_unsorted_list(self):
 
         results = []
         with Session(self.engine) as session:
-            cmd = select(Item).where(Item.store == None)
+            cmd = select(Item).where(Item.stores == None)
             items = session.exec(cmd).all()
 
             if not items:
@@ -123,12 +128,12 @@ class Data():
             items = store.shopping_list
             if not items:
                 results.append(f'-- Nothing to shop for at {store.name} --')
-
-            for item in items:
-                if(item.purchase_date):
-                    results.append(f' - [x] {item}')
-                else:
-                    results.append(f' - [ ] {item}')
+            else:
+                for item in items:
+                    if(item.purchase_date):
+                        results.append(f' - [x] {item}')
+                    else:
+                        results.append(f' - [ ] {item}')
         return results
 
     def get_engine(self):
index 966e2cfef6a6ec5e2ee7596ac8d9f12b0c3b955f..1fbc3fbe48ba9c7a5650ad908d3822f5f3a6372c 100644 (file)
@@ -17,6 +17,10 @@ def add_store(c, name):
     result = Data().add_store(name)
     print(result)
 
+@task
+def buy(c, item_id):
+    result = Data().purchase_item(item_id)
+    print(result)
 
 @task
 def list(c, store_id):
@@ -24,10 +28,23 @@ def list(c, store_id):
     for item in items:
         print(item)
 
+@task
+def list_stores(c):
+    items = Data().get_stores()
+    for item in items:
+        print(item)
+
+@task
+def clear_list(c, store_id):
+    Data().clear_list(store_id)
+
+@task
+def clear_all(c, store_id):
+    Data().clear_list(store_id, clear_all=True)
     
 @task
-def list_unsorted(c, store_id):
-    items = Data().list_unsorted()
+def list_unsorted(c):
+    items = Data().get_unsorted_list()
     for item in items:
         print(item)
 
@@ -36,3 +53,4 @@ def assign(c, store_id, item_id):
     result = Data().assign_store(store_id, item_id)
     print(result)
 
+