Products can now be searched using search term

This commit is contained in:
2024-01-15 21:47:18 +00:00
parent 40d7469321
commit 36a04d58e1
4 changed files with 36 additions and 7 deletions

View File

@ -51,15 +51,18 @@ class ProductController(DatabaseController):
return products
def read_all(self, category: str = "") -> list[Product] | None:
def read_all(self, category: str = "", search_term: str = "") -> list[Product] | None:
params = [
"%" + category + "%"
"%" + category + "%",
"%" + search_term + "%"
]
cursor = self._conn.execute(
"""SELECT * FROM Products
INNER JOIN Categories ON Products.categoryID = Categories.id
WHERE Categories.name LIKE ? """,
WHERE Categories.name LIKE ?
AND Products.name LIKE ?
""",
params
)
rows = cursor.fetchall()