diff --git a/app.py b/app.py
index 116eb5b4982e9344990ab9eefc678c9f6d3d2fbc..267f523008df6de475880a2ff462eb1f57472a9f 100644
--- a/app.py
+++ b/app.py
@@ -6,6 +6,7 @@ from modules.login import login_route
from modules.comment import comment_route
from modules.register import register_route
from modules.admin import admin_route
+from modules.page import page_route
from modules.tools.token import validate_login_token
app = Flask(__name__)
@@ -16,6 +17,7 @@ app.register_blueprint(login_route)
app.register_blueprint(register_route)
app.register_blueprint(comment_route)
app.register_blueprint(admin_route)
+app.register_blueprint(page_route)
cors = CORS(app)
diff --git a/database/database.py b/database/database.py
index dfa67bc8a9a1ad9d3de4592d11f281f8d7432aef..35fedb44cb123bd2741fcdfc16d7605d14544ff8 100644
--- a/database/database.py
+++ b/database/database.py
@@ -11,7 +11,7 @@ class User(mongo.Document):
password = mongo.StringField(required=True)
name = mongo.StringField(required=True)
role = mongo.IntField(required=True)
- page_list = mongo.ListField(mongo.ReferenceField("Page"))
+ page_list = mongo.ListField(mongo.ReferenceField("VizData"))
def to_json(self):
data = self.to_mongo()
@@ -25,15 +25,15 @@ class Reply(mongo.EmbeddedDocument):
class Comment(mongo.Document):
commenter_id = mongo.StringField(max_length=20, required=True)
comment_text = mongo.StringField(required=True)
- page = mongo.ReferenceField('Page', required=True)
+ page = mongo.ReferenceField('VizData', required=True)
reply = mongo.EmbeddedDocumentField('Reply')
class VizData(mongo.Document):
name = mongo.StringField(required = True)
level = mongo.IntField(required= True)
- value = mongo.IntField(required = True)
+ value = mongo.LongField(required = True)
+ year = mongo.IntField(required=True)
subdata = mongo.ListField(mongo.ReferenceField("VizData"))
- detail = mongo.StringField()
if __name__ == "__main__":
diff --git a/modules/page.py b/modules/page.py
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..878e0d4f5d2d419dcdedbd1667fd437ce7f56ccb 100644
--- a/modules/page.py
+++ b/modules/page.py
@@ -0,0 +1,52 @@
+import json
+import jwt
+import datetime
+from flask import Blueprint, jsonify, request, current_app
+from database import database as db
+from modules.tools.token import Token, validate_login_token
+from modules.tools.roles import Roles
+
+page_route = Blueprint('page', __name__, template_folder="templates")
+
+@page_route.route("/api/page/get-top", methods=["POST"])
+def get_top_page():
+ year = request.get_json().get("year")
+ try:
+ vdata = db.VizData.objects.get(level = 0, year = year)
+ return jsonify({
+ "status":200,
+ "data": vdata,
+ "subdata": [child for child in vdata.subdata]
+ })
+ except Exception as e:
+ return jsonify({
+ "status": 500,
+ "message": str(e)
+ })
+
+@page_route.route("/api/page/get", methods=["POST"])
+def get_page():
+ data_id = request.get_json().get("data_id")
+ try:
+ vdata = db.VizData.objects.with_id(data_id)
+ if vdata is not None:
+ return jsonify({
+ "status":200,
+ "data":vdata,
+ "subdata":[child for child in vdata.subdata]
+ })
+
+
+@page_route.route("/api/hidden/add-data", methods=["POST"])
+def add_page():
+ data = request.get_json()
+ name = data.get("name")
+ value = data.get("value")
+ level = data.get("level")
+ year = data.get("year")
+
+ db.VizData(name=name, value=value, level=level, year=year).save()
+ return jsonify({
+ "status":200,
+ "message":"data added, but this endpoint is only for testing"
+ })