]> apps.delaporte.us Git - matrix-shop-bot.git/blobdiff - matrix_shop_bot/db.py
Fixup
[matrix-shop-bot.git] / matrix_shop_bot / db.py
index 407a12a733633fcc82e6f02269fbd69ece961615..6b7c7ab33d44efd8781683100b5ffcde5c9b66b8 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,14 +128,26 @@ 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 remove_item(self, item_id):
+        with Session(self.engine) as session:
+            item = session.exec(_get_with_id(Item, item_id)).first()
+            session.delete(item)
+            session.commit()
+
+    def remove_store(self, store_id):
+        with Session(self.engine) as session:
+            store = session.exec(_get_with_id(Store, store_id)).first()
+            session.delete(store)
+            session.commit()
+
     def get_engine(self):
         return create_engine(f"sqlite:///{self.file}")