#5 Started wiring up endpoints do display user stats

This commit is contained in:
Luke Else 2024-02-01 01:44:02 +00:00
parent fee4a19e3f
commit dd243e9c72
5 changed files with 39 additions and 4 deletions

View File

@ -50,7 +50,7 @@ class StatsController(DatabaseController):
]
cursor = self._conn.execute(
"""SELECT * FROM Stats
"""SELECT * FROM Views
WHERE productID = ?
""",
params

View File

@ -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 #

33
controllers/web/stats.py Normal file
View File

@ -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/<int:id>')
def view_product_stats(id: int):
db = StatsController()
data = db.read_product(id)
return ""
@blueprint.route('/user/<int:id>')
def view_user_stats(id: int):
db = StatsController()
data = db.read_user(id)
return ""

View File

@ -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 """

View File

@ -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
)