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