""" 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(): """ Main page to view all of the statistics for the site """ db = StatsController() data = db.read() test = list(map(lambda d: d.productID, data)) for i in test: print(i) return render_template("index.html", content="stats.html", data=test) @blueprint.route('/product/') def view_product_stats(id: int): """ Page to view statistics for a given product """ db = StatsController() data = db.read_product(id) return render_template("index.html", content="stats.html", data=data) @blueprint.route('/user/') def view_user_stats(id: int): """ Page to view statistics for a given user """ db = StatsController() data = db.read_user(id) return render_template("index.html", content="stats.html", data=data)