#5 Started wiring up endpoints do display user stats
This commit is contained in:
parent
fee4a19e3f
commit
dd243e9c72
@ -50,7 +50,7 @@ class StatsController(DatabaseController):
|
|||||||
]
|
]
|
||||||
|
|
||||||
cursor = self._conn.execute(
|
cursor = self._conn.execute(
|
||||||
"""SELECT * FROM Stats
|
"""SELECT * FROM Views
|
||||||
WHERE productID = ?
|
WHERE productID = ?
|
||||||
""",
|
""",
|
||||||
params
|
params
|
||||||
|
@ -5,11 +5,13 @@ from flask import redirect, Blueprint, session
|
|||||||
|
|
||||||
from . import user
|
from . import user
|
||||||
from . import product
|
from . import product
|
||||||
|
from . import stats
|
||||||
|
|
||||||
blueprint = Blueprint('main', __name__)
|
blueprint = Blueprint('main', __name__)
|
||||||
|
|
||||||
blueprint.register_blueprint(user.blueprint)
|
blueprint.register_blueprint(user.blueprint)
|
||||||
blueprint.register_blueprint(product.blueprint)
|
blueprint.register_blueprint(product.blueprint)
|
||||||
|
blueprint.register_blueprint(stats.blueprint)
|
||||||
|
|
||||||
|
|
||||||
# CONTEXTS #
|
# CONTEXTS #
|
||||||
|
33
controllers/web/stats.py
Normal file
33
controllers/web/stats.py
Normal 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 ""
|
@ -11,7 +11,7 @@ class Stats:
|
|||||||
self.id = 0
|
self.id = 0
|
||||||
self.userID = 0
|
self.userID = 0
|
||||||
self.productID = 0
|
self.productID = 0
|
||||||
self.viewDate = datetime.now()
|
self.viewDate: datetime = datetime.now()
|
||||||
|
|
||||||
def __init__(self, product_id: int, user_id: int):
|
def __init__(self, product_id: int, user_id: int):
|
||||||
""" Construct a view with the user and product class """
|
""" Construct a view with the user and product class """
|
||||||
|
@ -50,7 +50,7 @@ CREATE TABLE IF NOT EXISTS Orders (
|
|||||||
REFERENCES Users (id)
|
REFERENCES Users (id)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
ON UPDATE NO ACTION,
|
ON UPDATE NO ACTION,
|
||||||
orderDate DATE NOT NULL
|
orderDate TIMESTAMP NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Views (
|
CREATE TABLE IF NOT EXISTS Views (
|
||||||
@ -63,5 +63,5 @@ CREATE TABLE IF NOT EXISTS Views (
|
|||||||
REFERENCES Users (id)
|
REFERENCES Users (id)
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION,
|
ON UPDATE NO ACTION,
|
||||||
viewDate DATE NOT NULL
|
viewDate TIMESTAMP NOT NULL
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user