From 728034dda00fbefcdb86861afd7fbead552c4245 Mon Sep 17 00:00:00 2001 From: Casey Becking Date: Sun, 17 Nov 2024 06:28:36 -0800 Subject: [PATCH] working istitution page --- Pipfile | 1 + README.md | 3 +- api/categories_group/models.py | 2 +- api/institution/controllers.py | 3 +- api/institution_account/controllers.py | 3 +- api/user/controllers.py | 1 + api/user/models.py | 14 ++ app/institution/controllers.py | 10 +- app/institution_account/controllers.py | 10 +- app/static/js/institution/institution.js | 32 +++ .../institution_account.js | 0 app/templates/institution/index.html | 183 +++++++++++++++--- app/templates/institution_account/index.html | 67 ++++++- 13 files changed, 285 insertions(+), 44 deletions(-) create mode 100644 app/static/js/institution/institution.js create mode 100644 app/static/js/institution_account/institution_account.js diff --git a/Pipfile b/Pipfile index 6b9a18e..f626525 100644 --- a/Pipfile +++ b/Pipfile @@ -14,6 +14,7 @@ flask-restx = "*" flask-login = "*" python-dotenv = "*" pylint = "*" +requests = "*" [dev-packages] diff --git a/README.md b/README.md index b6afc94..6c088fe 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ flask run ### Plugins ## Roadmap and releases -### Models +### Required Models - Users - Email - Password @@ -58,6 +58,7 @@ flask run - Amount - Transaction Type +### Nice to haves - Items (thought here is to be able to track the items that make up the transaction) - Merchant - Tags diff --git a/api/categories_group/models.py b/api/categories_group/models.py index 93da3ad..2a3363e 100644 --- a/api/categories_group/models.py +++ b/api/categories_group/models.py @@ -12,7 +12,7 @@ def __init__(self, user_id, name): def __repr__(self): return '' % self.name - + def to_dict(self): return { 'id': self.id, diff --git a/api/institution/controllers.py b/api/institution/controllers.py index ef836f9..94c2742 100644 --- a/api/institution/controllers.py +++ b/api/institution/controllers.py @@ -31,6 +31,5 @@ def post(self): def get(self): institutions = InstitutionModel.query.all() - _isntitutions = [] - _isntitutions.append([institution.to_dict() for institution in institutions]) + _isntitutions = [institution.to_dict() for institution in institutions] return make_response(jsonify({'institutions': _isntitutions}), 200) diff --git a/api/institution_account/controllers.py b/api/institution_account/controllers.py index eedd48a..687e33c 100644 --- a/api/institution_account/controllers.py +++ b/api/institution_account/controllers.py @@ -37,6 +37,5 @@ def post(self): def get(self): accounts = InstitutionAccountModel.query.all() - _accounts = [] - _accounts.append([account.to_dict() for account in accounts]) + _accounts = [account.to_dict() for account in accounts] return make_response(jsonify({'accounts': _accounts}), 200) diff --git a/api/user/controllers.py b/api/user/controllers.py index 27b44ab..fb684ff 100644 --- a/api/user/controllers.py +++ b/api/user/controllers.py @@ -42,5 +42,6 @@ def post(self): def get(self): users = _user_model.query.all() + users = [user.to_dict() for user in users] return make_response(jsonify({'users': users}), 200) diff --git a/api/user/models.py b/api/user/models.py index 8d3df92..43474b5 100644 --- a/api/user/models.py +++ b/api/user/models.py @@ -20,6 +20,20 @@ def __init__(self, email, username, password, first_name, last_name): self.last_name = last_name self.api_key = None # Initialize without an API key + def __repr__(self): + return '' % self.username + + def to_dict(self): + return { + 'id': self.id, + 'email': self.email, + 'username': self.username, + 'first_name': self.first_name, + 'last_name': self.last_name, + 'created_at': self.created_at, + 'updated_at': self.updated_at + } + def generate_api_key(self): """Generate a new unique API key and save it to the database.""" self.api_key = secrets.token_hex(32) # Generate a 64-character API key diff --git a/app/institution/controllers.py b/app/institution/controllers.py index c898bb5..804931b 100644 --- a/app/institution/controllers.py +++ b/app/institution/controllers.py @@ -1,9 +1,15 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, url_for, session from flask_login import login_required +import requests institution_blueprint = Blueprint('institution', __name__) @institution_blueprint.route('/institution') @login_required def institution(): - return render_template('institution/index.html') + api_url = url_for('institution', _external=True) + response = requests.get(api_url) + institutions = response.json().get('institutions', []) + user_id = session.get('_user_id') + + return render_template('institution/index.html', institutions=institutions, user_id=user_id) diff --git a/app/institution_account/controllers.py b/app/institution_account/controllers.py index b7f1b96..1553e92 100644 --- a/app/institution_account/controllers.py +++ b/app/institution_account/controllers.py @@ -1,9 +1,15 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, url_for from flask_login import login_required +import requests + institution_account_blueprint = Blueprint('institution_account', __name__) @institution_account_blueprint.route('/account') @login_required def institution_account(): - return render_template('institution_account/index.html') + api_url = url_for('institution_account', _external=True) + response = requests.get(api_url) + accounts = response.json().get('accounts', []) + + return render_template('institution_account/index.html', accounts=accounts) diff --git a/app/static/js/institution/institution.js b/app/static/js/institution/institution.js new file mode 100644 index 0000000..2b8a4b2 --- /dev/null +++ b/app/static/js/institution/institution.js @@ -0,0 +1,32 @@ +function instituionFormSubmit(event) { + event.preventDefault(); + + const institutionName = document.getElementById('institutionName').value; + const institutionLocation = document.getElementById('institutionLocation').value; + const institutionDescription = document.getElementById('institutionDescription').value; + const user_id = document.getElementById('user_id').value; + + const data = { + name: institutionName, + location: institutionLocation, + description: institutionDescription, + user_id: user_id + }; + + fetch('/api/institution', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }) + .then(response => response.json()) + .then(data => { + console.log('Success:', data); + // redirect to the institutions page + window.location.href = '/institution'; + }) + .catch((error) => { + console.error('Error:', error); + }); +} \ No newline at end of file diff --git a/app/static/js/institution_account/institution_account.js b/app/static/js/institution_account/institution_account.js new file mode 100644 index 0000000..e69de29 diff --git a/app/templates/institution/index.html b/app/templates/institution/index.html index e3b5041..fdcfa9a 100644 --- a/app/templates/institution/index.html +++ b/app/templates/institution/index.html @@ -3,40 +3,161 @@ {% block extra_css %} {% endblock extra_css %} {% block content %} - - - -
- -
-
- - -
-
-
-

Institution

- -
- -
+
-
+
+
+ + +
+
+
+

Institution

+ +
+
-
- +
-
- + +
+
+
+
+

Institutions

- {% block footer %} - {% include "partials/footer.html" %} - {% endblock footer %} -
- -{% endblock content %} \ No newline at end of file +
+
+ +
+ +
+
+
+ +
+ + + +
+

Add Instiutions with the + button

+ +
+
+ + + + + + + + + + + + + {% for institution in institutions %} + + + + + + + + + {% endfor %} + +
+
+ + +
+
NameDescriptionLast UpdatedAction
+
+ + +
+
{{ institution.name }}{{ institution.description }}{{ institution.updated_at }} + +
+
+
+
+
+
+
+ +
+ +
+ + {% block footer %} + {% include "partials/footer.html" %} + {% endblock footer %} +
+ +{% endblock content %} +{% block extra_js %} + +{% endblock extra_js %} diff --git a/app/templates/institution_account/index.html b/app/templates/institution_account/index.html index 24c6ce2..7181345 100644 --- a/app/templates/institution_account/index.html +++ b/app/templates/institution_account/index.html @@ -3,9 +3,6 @@ {% block extra_css %} {% endblock extra_css %} {% block content %} - - -
@@ -28,6 +25,70 @@

Account

+
+
+
+
+

Accounts

+ +
+
+ +
+
+
+ +
+

Add accounts with the + button

+ +
+
+ + + + + + + + + + + + + + {% for account in accounts %} + + + + + + + + + + + + {% endfor %} + +
+
+ + +
+
IDNameDateTotalStatusAction
+
+ + +
+
#{{ account.id }}{{ account.name }}{{ account.date }}{{ account.total }}Paid + +
+
+
+
+
+
+