30 lines
No EOL
1.3 KiB
Python
30 lines
No EOL
1.3 KiB
Python
from flask import Flask, request
|
|
|
|
from eligibility_api.elig_api_exceptions import ApiParamException
|
|
from coordinates import check_coordinates_args, check_coordinates_area
|
|
from ipe_fetcher.axione import AXIONE_MAX_AREA, Axione
|
|
|
|
class EligibilityApiRoutes:
|
|
def __init__(self, flask_app: Flask, axione_ipe: Axione):
|
|
self.flask_app = flask_app
|
|
self.axione_ipe = axione_ipe
|
|
|
|
def add_routes(self):
|
|
|
|
@self.flask_app.route("/eligibilite/axione", methods=["GET"])
|
|
def get_axione_eligibility_per_immeuble():
|
|
refimmeuble = request.args.get("refimmeuble")
|
|
if not refimmeuble:
|
|
raise ApiParamException("You need to specify path parameter 'refimmeuble'")
|
|
return self.axione_ipe.get_eligibilite_per_id_immeuble(refimmeuble)
|
|
|
|
|
|
@self.flask_app.route("/eligibilite/axione/coord", methods=["GET"])
|
|
def get_axione_eligibility_per_coordinates():
|
|
args = request.args
|
|
try:
|
|
processed_args = check_coordinates_args(args)
|
|
coordinates = check_coordinates_area(processed_args, AXIONE_MAX_AREA)
|
|
return self.axione_ipe.getAreaBuildings(coordinates, {})
|
|
except ValueError:
|
|
raise ApiParamException("You need to specify path parameters 'swx' 'swy' 'nex' 'ney'") |