WMGZON/controllers/database/stats.py

57 lines
1.2 KiB
Python
Raw Normal View History

from .database import DatabaseController
from models.stats import Stats
class StatsController(DatabaseController):
FIELDS = ['id', 'userID', 'productID', 'viewDate']
TYPE = Stats
def __init__(self):
super().__init__()
def create(self, view: Stats):
params = [
view.userID,
view.productID,
view.viewDate
]
query = """
INSERT INTO Views
(userID, productID, viewDate)
VALUES (?, ?, ?)
"""
self.do(query, params)
def read(self) -> list[Stats] | None:
query = "SELECT * FROM Views"
self.get_many(query, [])
def read_product(self, product_id: int = 0) -> list[Stats] | None:
params = [
product_id
]
query = """
SELECT * FROM Views
WHERE productID = ?
"""
return self.get_many(query, params)
def read_user(self, user_id: int) -> list[Stats] | None:
params = [
user_id
]
query = """
SELECT * FROM Views
WHERE userID = ?
"""
self.get_many(query, params)
def update(self):
print("Doing work")
def delete(self):
print("Doing work")