From dd243e9c72e6504cb8f3debfb50239f2c078618c Mon Sep 17 00:00:00 2001 From: Luke Else Date: Thu, 1 Feb 2024 01:44:02 +0000 Subject: [PATCH] #5 Started wiring up endpoints do display user stats --- controllers/database/stats.py | 2 +- controllers/web/endpoints.py | 2 ++ controllers/web/stats.py | 33 +++++++++++++++++++++++++++++++++ models/stats.py | 2 +- scripts/create_tables.sql | 4 ++-- 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 controllers/web/stats.py diff --git a/controllers/database/stats.py b/controllers/database/stats.py index cff0db3..4656c12 100644 --- a/controllers/database/stats.py +++ b/controllers/database/stats.py @@ -50,7 +50,7 @@ class StatsController(DatabaseController): ] cursor = self._conn.execute( - """SELECT * FROM Stats + """SELECT * FROM Views WHERE productID = ? """, params diff --git a/controllers/web/endpoints.py b/controllers/web/endpoints.py index fc5f753..d707146 100644 --- a/controllers/web/endpoints.py +++ b/controllers/web/endpoints.py @@ -5,11 +5,13 @@ from flask import redirect, Blueprint, session from . import user from . import product +from . import stats blueprint = Blueprint('main', __name__) blueprint.register_blueprint(user.blueprint) blueprint.register_blueprint(product.blueprint) +blueprint.register_blueprint(stats.blueprint) # CONTEXTS # diff --git a/controllers/web/stats.py b/controllers/web/stats.py new file mode 100644 index 0000000..b984aeb --- /dev/null +++ b/controllers/web/stats.py @@ -0,0 +1,33 @@ +""" The user controller to manage all of the stats related endpoints + in the web app +""" +import json +from flask import Blueprint + +from flask import render_template, redirect, request, session, flash +from controllers.database.stats import StatsController +from models.stats import Stats +from models.users.user import User + +# Blueprint to append user endpoints to +blueprint = Blueprint("stats", __name__, url_prefix='/stats') + + +@blueprint.route('/') +def stats_index(): + db = StatsController() + data = db.read() + return "" + + +@blueprint.route('/product/') +def view_product_stats(id: int): + db = StatsController() + data = db.read_product(id) + return "" + +@blueprint.route('/user/') +def view_user_stats(id: int): + db = StatsController() + data = db.read_user(id) + return "" \ No newline at end of file diff --git a/models/stats.py b/models/stats.py index 291d258..cc00647 100644 --- a/models/stats.py +++ b/models/stats.py @@ -11,7 +11,7 @@ class Stats: self.id = 0 self.userID = 0 self.productID = 0 - self.viewDate = datetime.now() + self.viewDate: datetime = datetime.now() def __init__(self, product_id: int, user_id: int): """ Construct a view with the user and product class """ diff --git a/scripts/create_tables.sql b/scripts/create_tables.sql index 6aa5ac3..865d29e 100644 --- a/scripts/create_tables.sql +++ b/scripts/create_tables.sql @@ -50,7 +50,7 @@ CREATE TABLE IF NOT EXISTS Orders ( REFERENCES Users (id) ON DELETE CASCADE ON UPDATE NO ACTION, - orderDate DATE NOT NULL + orderDate TIMESTAMP NOT NULL ); CREATE TABLE IF NOT EXISTS Views ( @@ -63,5 +63,5 @@ CREATE TABLE IF NOT EXISTS Views ( REFERENCES Users (id) ON DELETE NO ACTION ON UPDATE NO ACTION, - viewDate DATE NOT NULL + viewDate TIMESTAMP NOT NULL )