api_v1.4/bootstrap.py

85 lines
3.5 KiB
Python
Raw Normal View History

"""
Main
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2021 Project Author name guillermo.gutierrezmorote@concordia.ca
Project Collaborator name peteryefi@gmail.com
"""
import flask
import yaml
from flask_restful import Api
2023-01-13 12:01:13 -05:00
from hub_api.city_info import CityInfo, City
from hub_api.geometry import Geometry
from hub_api.greenery_catalog import GreeneryCatalogEntries
from hub_api.greenery_catalog import GreeneryCatalogEntry
from hub_api.greenery_catalog import GreeneryCatalogNames
from hub_api.construction_catalog import ConstructionCatalogEntries
from hub_api.construction_catalog import ConstructionCatalogEntry
from hub_api.construction_catalog import ConstructionCatalogNames
from hub_api.usage_catalog import UsageCatalogEntries
from hub_api.usage_catalog import UsageCatalogEntry
from hub_api.usage_catalog import UsageCatalogNames
from hub_api.heat_pump import HeatPump
from hub_api.lca import MaterialLCACatalog
from hub_api.lca import MaterialLCACalculations
from hub_api.construction import Construction
from hub_api.usage import Usage
from hub_api.energy_demand import EnergyDemand
from hub_api.session import SessionStart, SessionEnd, KeepSessionAlive
from hub_api.uptime import Uptime
from hub_api.greenery import Greenery
2023-01-11 19:56:51 -05:00
from hub_api.user import User, UserLogin
2023-01-17 19:02:49 -05:00
from flasgger import LazyJSONEncoder, Swagger
app = flask.Flask('gamification')
app.json_encoder = LazyJSONEncoder
api = Api(app)
with open("hub_api/docs/openapi-specs.yml", "r") as stream:
swagger_config = {
"headers": [],
"specs": [
{
"endpoint": 'apispec',
"route": '/apispec.json',
"rule_filter": lambda rule: True, # all in
"model_filter": lambda tag: True, # all in
}
],
"static_url_path": "/flasgger_static",
"specs_route": "/api-docs/",
"openapi": "3.0.0"
}
try:
Swagger(app, template=yaml.safe_load(stream), config=swagger_config)
except yaml.YAMLError as exc:
print(exc)
api.add_resource(Uptime, '/v1.4/uptime')
api.add_resource(Geometry, '/v1.4/geometry')
api.add_resource(GreeneryCatalogEntry, '/v1.4/greenery-catalog/entry')
api.add_resource(GreeneryCatalogEntries, '/v1.4/greenery-catalog/entries')
api.add_resource(GreeneryCatalogNames, '/v1.4/greenery-catalog/names')
api.add_resource(ConstructionCatalogEntry, '/v1.4/construction-catalog/entry')
api.add_resource(ConstructionCatalogEntries, '/v1.4/construction-catalog/entries')
api.add_resource(ConstructionCatalogNames, '/v1.4/construction-catalog/names')
2023-01-17 19:02:49 -05:00
api.add_resource(Construction, '/v1.4/construction/<int:city_id>')
api.add_resource(UsageCatalogEntry, '/v1.4/usage-catalog/entry')
api.add_resource(UsageCatalogEntries, '/v1.4/usage-catalog/entries')
api.add_resource(UsageCatalogNames, '/v1.4/usage-catalog/names')
api.add_resource(Usage, '/v1.4/usage')
2023-01-17 19:02:49 -05:00
api.add_resource(EnergyDemand, '/v1.4/energy-demand/<int:city_id>')
# api.add_resource(LCA, '/v1.4/lca')
2023-01-17 19:02:49 -05:00
api.add_resource(MaterialLCACatalog, '/v1.4/material_lca_catalog/entries/<int:city_id>')
api.add_resource(MaterialLCACalculations, '/v1.4/material_lca_catalog/calculations/<int:city_id>')
api.add_resource(HeatPump, '/v1.4/heat-pump/<int:city_id>')
api.add_resource(User, '/v1.4/user')
2023-01-11 19:56:51 -05:00
api.add_resource(UserLogin, '/v1.4/user/login')
api.add_resource(SessionStart, '/v1.4/session/start')
api.add_resource(SessionEnd, '/v1.4/session/end')
api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive')
2023-01-17 19:02:49 -05:00
api.add_resource(CityInfo, '/v1.4/city/<int:city_id>')
2023-01-13 12:01:13 -05:00
api.add_resource(City, '/v1.4/city')
api.add_resource(Greenery, '/v1.4/greenery')