| from flask_login import login_required, current_user | from flask_login import login_required, current_user | ||||
| from .models import Resource, User | from .models import Resource, User | ||||
| from .schemas import UserSchema, ToolSchema, PracticeSchema, BookSchema | from .schemas import UserSchema, ToolSchema, PracticeSchema, BookSchema | ||||
| from .relationships import * | |||||
| import pandas as pd | |||||
| import json | |||||
| api = Blueprint('api', __name__) | api = Blueprint('api', __name__) | ||||
| # function to get different types from the Resource database table | # function to get different types from the Resource database table | ||||
| def get_resource_json(type): | |||||
| resources = Resource.query.filter_by(type=type) | |||||
| if (type=='tool'): | |||||
| def get_resource_json(resource_type): | |||||
| resources = Resource.query.filter_by(type=resource_type) | |||||
| if (resource_type=='tool'): | |||||
| resources_schema = ToolSchema(many=True) | resources_schema = ToolSchema(many=True) | ||||
| elif (type=='practice'): | |||||
| elif (resource_type=='practice'): | |||||
| resources_schema = PracticeSchema(many=True) | resources_schema = PracticeSchema(many=True) | ||||
| elif (type=='book'): | |||||
| elif (resource_type=='book'): | |||||
| resources_schema = BookSchema(many=True) | resources_schema = BookSchema(many=True) | ||||
| result = resources_schema.dump(resources) | result = resources_schema.dump(resources) | ||||
| # return all rows as a JSON array of objects | # return all rows as a JSON array of objects | ||||
| # route for exporting all tools in database | # route for exporting all tools in database | ||||
| @api.route('/api/tools') | @api.route('/api/tools') | ||||
| def get_tools(): | |||||
| type = 'tool' | |||||
| output = get_resource_json(type) | |||||
| def get_tools_json(): | |||||
| resource_type = 'tool' | |||||
| output = get_resource_json(resource_type) | |||||
| return output | return output | ||||
| # route for exporting all practices in database | # route for exporting all practices in database | ||||
| @api.route('/api/practices') | @api.route('/api/practices') | ||||
| def get_practices(): | def get_practices(): | ||||
| type = 'practice' | |||||
| output = get_resource_json(type) | |||||
| resource_type = 'practice' | |||||
| output = get_resource_json(resource_type) | |||||
| return output | return output | ||||
| # route for exporting all books in database | # route for exporting all books in database | ||||
| @api.route('/api/books') | @api.route('/api/books') | ||||
| def get_books(): | def get_books(): | ||||
| type = 'book' | |||||
| output = get_resource_json(type) | |||||
| resource_type = 'book' | |||||
| output = get_resource_json(resource_type) | |||||
| return output | return output |