2024-01-28 11:59:04 +00:00
|
|
|
from .database import DatabaseController
|
|
|
|
from models.category import Category
|
|
|
|
|
|
|
|
|
|
|
|
class CategoryController(DatabaseController):
|
|
|
|
FIELDS = ['id', 'name']
|
2024-02-04 23:47:00 +00:00
|
|
|
TYPE = Category
|
2024-01-28 11:59:04 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def create(self, category: Category):
|
|
|
|
params = [
|
|
|
|
category.name,
|
|
|
|
]
|
2024-02-04 23:47:00 +00:00
|
|
|
query = "INSERT INTO Categories (name) VALUES (?)"
|
2024-01-28 11:59:04 +00:00
|
|
|
|
2024-02-04 23:47:00 +00:00
|
|
|
self.do(query, params)
|
2024-01-28 11:59:04 +00:00
|
|
|
|
|
|
|
def read(self, id: int = 0) -> Category | None:
|
|
|
|
params = [
|
|
|
|
id
|
|
|
|
]
|
2024-02-04 23:47:00 +00:00
|
|
|
query = "SELECT * FROM Categories WHERE id = ?"
|
2024-01-28 11:59:04 +00:00
|
|
|
|
2024-02-04 23:47:00 +00:00
|
|
|
return self.get_one(query, params)
|
2024-01-28 11:59:04 +00:00
|
|
|
|
|
|
|
def read_all(self) -> list[Category] | None:
|
2024-02-04 23:47:00 +00:00
|
|
|
query = "SELECT * FROM Categories"
|
|
|
|
return self.get_many(query, [])
|
2024-01-28 11:59:04 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
print("Doing work")
|
|
|
|
|
|
|
|
def delete(self):
|
|
|
|
print("Doing work")
|