Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add api get for version number #15

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions liwo_services/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

# side effect loads the env
import sys
sys.path.append('.')

sys.path.append(".")
import liwo_services
import liwo_services.export
import liwo_services.settings
Expand Down Expand Up @@ -62,7 +63,7 @@ def create_app_db():

# Create a URL route in our application for "/"
@v1.route("/")
@v2.route("/") # /api/v2/
@v2.route("/") # /api/v2/
def home():
"""
This function just responds to the browser ULR
Expand All @@ -72,6 +73,7 @@ def home():
"""
return {"liwo_service": "Hello World"}


@v1.route("/liwo.ws/Authentication.asmx/Login", methods=["OPTIONS", "POST"])
@v2.route("/liwo.ws/Authentication.asmx/Login", methods=["OPTIONS", "POST"])
@cache.cached()
Expand All @@ -85,10 +87,10 @@ def loadLayerSets():

TODO: remove Login part and only return json generated by postgresql function
"""
qLayerSet = text("SELECT website.sp_selectjson_maplayersets_groupedby_mapcategories()")
rs = db.session.execute(
qLayerSet
qLayerSet = text(
"SELECT website.sp_selectjson_maplayersets_groupedby_mapcategories()"
)
rs = db.session.execute(qLayerSet)

result = rs.fetchall()

Expand Down Expand Up @@ -116,6 +118,7 @@ def loadLayerSets():

return {"d": layersets_string}


@v1.route(
"/liwo.ws/Tools/FloodImage.asmx/GetScenariosPerBreachGeneric", methods=["POST"]
)
Expand Down Expand Up @@ -153,12 +156,15 @@ def loadBreachLayer():
breach_id = body["breachid"]

# define query with parameters
query = text("SELECT website.sp_selectjson_maplayerset_floodscen_breachlocation_id_generic(:breach_id, :set_name)")
query = text(
"SELECT website.sp_selectjson_maplayerset_floodscen_breachlocation_id_generic(:breach_id, :set_name)"
)

rs = db.session.execute(query, {"breach_id": breach_id, "set_name": set_name})
result = rs.fetchone()
return {"d": json.dumps(result[0])}


@v2.route("/load_breach_layer", methods=["POST"])
@cache.cached(make_cache_key=_post_request_cache_key)
def load_breach_layer():
Expand All @@ -179,6 +185,7 @@ def load_breach_layer():
result = rs.fetchone()
return json.dumps(result[0])


@v2.route("/get_breach_id", methods=["POST"])
@cache.cached(make_cache_key=_post_request_cache_key)
def get_breach_id():
Expand All @@ -193,26 +200,56 @@ def get_breach_id():
body = request.json
scenario_id = body["scenario_id"]

query = text("SELECT breachlocations_id FROM static_information.tbl_floodsimulations WHERE id=(:scenario_id)")
query = text(
"SELECT breachlocations_id FROM static_information.tbl_floodsimulations WHERE id=(:scenario_id)"
)

rs = db.session.execute(query, {"scenario_id": scenario_id})
result = rs.fetchone()
return json.dumps(result[0])


@v2.route("/filter_variants", methods=["GET"])
def filter_variants():
"""
Return list of filter properties for variants
"""

properties = ["Overschrijdingsfrequentie", "Status SVK", "Bres", "Moment van falen", "Toestand SVK", "Waterstandsverloop"
, "Bresvorming dijk", "Bresvorming kunstwerk", "Standzekerheid achterliggende lijnelementen", "Ingrepen in watersysteem", "Klimaatscenario"
, "VariantKeuze_1", "VariantKeuze_2", "VariantKeuze_3", "VariantKeuze_4", "VariantKeuze_5", "VariantKeuze_6"]
properties = [
"Overschrijdingsfrequentie",
"Status SVK",
"Bres",
"Moment van falen",
"Toestand SVK",
"Waterstandsverloop",
"Bresvorming dijk",
"Bresvorming kunstwerk",
"Standzekerheid achterliggende lijnelementen",
"Ingrepen in watersysteem",
"Klimaatscenario",
"VariantKeuze_1",
"VariantKeuze_2",
"VariantKeuze_3",
"VariantKeuze_4",
"VariantKeuze_5",
"VariantKeuze_6",
]

return json.dumps(properties)


@v2.route("/version_number", methods=["GET"])
def version_number():
"""
Returns the version number LIWO database through the api.Q!
"""
query = text("SELECT * FROM static_information_geodata.versie_nummer")
rs = db.session.execute(query)
result = rs.fetchone()

return result


@v1.route("/liwo.ws/Maps.asmx/GetLayerSet", methods=["POST"])
@v2.route("/liwo.ws/Maps.asmx/GetLayerSet", methods=["POST"])
@cache.cached(make_cache_key=_post_request_cache_key)
Expand Down Expand Up @@ -294,6 +331,7 @@ def download_zip():
)
return resp


app.register_blueprint(v1, name="api_v1", url_prefix="/api/v1")
app.register_blueprint(v2, name="api_v2", url_prefix="/api/v2")
app.register_blueprint(v1, name="root", url_prefix="/")
Expand All @@ -304,5 +342,5 @@ def download_zip():
portnumber = 80
if os.environ.get("PORT") is not None:
portnumber = os.environ.get("PORT")

app.run(host="0.0.0.0", debug=True, port=portnumber, threaded=True)
1 change: 0 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ tox==3.24.*
coverage==6.3.*
Sphinx==4.4.*
twine==3.8.*
Click==8.0.*
pytest==7.0.*
pytest-runner==5.3.*
commitizen==2.20.*
Expand Down
Loading