Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Improving Python REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
emi420 committed Oct 2, 2023
1 parent 774ae6f commit d029b1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 5 additions & 4 deletions python/dbapi/api/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

from .db import UnderpassDB

RESULTS_PER_PAGE = 100
RESULTS_PER_PAGE = 500
RESULTS_PER_PAGE_LIST = 100

# TODO: improve this code
def tagsQueryFilter(tagsQuery, table):
Expand Down Expand Up @@ -181,7 +182,7 @@ def getPolygonsList(
) SELECT jsonb_agg(t_features.feature) as result FROM t_features;".format(
"ST_Intersects(\"geom\", ST_GeomFromText('POLYGON(({0}))', 4326) )".format(area) if area else "1=1 ",
"AND (" + tagsQueryFilter(tags, "ways_poly") + ")" if tags else "",
"ORDER BY ways_poly.timestamp DESC LIMIT " + str(RESULTS_PER_PAGE),
"ORDER BY ways_poly.timestamp DESC LIMIT " + str(RESULTS_PER_PAGE_LIST) + " OFFSET {0}".format(page * RESULTS_PER_PAGE_LIST) if page else "",
)
return self.underpassDB.run(query, responseType, True)

Expand All @@ -206,7 +207,7 @@ def getLinesList(
) SELECT jsonb_agg(t_features.feature) as result FROM t_features;".format(
"ST_Intersects(\"geom\", ST_GeomFromText('POLYGON(({0}))', 4326) )".format(area) if area else "1=1 ",
"AND (" + tagsQueryFilter(tags, "ways_line") + ")" if tags else "",
"ORDER BY ways_line.timestamp DESC LIMIT " + str(RESULTS_PER_PAGE) + " OFFSET {0}".format(page * RESULTS_PER_PAGE) if page else "",
"ORDER BY ways_line.timestamp DESC LIMIT " + str(RESULTS_PER_PAGE_LIST) + " OFFSET {0}".format(page * RESULTS_PER_PAGE_LIST) if page else "",
)
return self.underpassDB.run(query, responseType, True)

Expand All @@ -231,7 +232,7 @@ def getNodesList(
) SELECT jsonb_agg(t_features.feature) as result FROM t_features;".format(
"ST_Intersects(\"geom\", ST_GeomFromText('POLYGON(({0}))', 4326) )".format(area) if area else "1=1 ",
"AND (" + tagsQueryFilter(tags, "nodes") + ")" if tags else "",
"ORDER BY nodes.timestamp DESC LIMIT " + str(RESULTS_PER_PAGE) + " OFFSET {0}".format(page * RESULTS_PER_PAGE) if page else "",
"ORDER BY nodes.timestamp DESC LIMIT " + str(RESULTS_PER_PAGE_LIST) + " OFFSET {0}".format(page * RESULTS_PER_PAGE_LIST) if page else "",
)
return self.underpassDB.run(query, responseType, True)

Expand Down
3 changes: 1 addition & 2 deletions python/restapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ class OsmchangeValidateRequest(BaseModel):

class RawRequest(BaseModel):
area: str = None
key: str = None
value: str = None
tags: str = None
page: int = None

0 comments on commit d029b1a

Please sign in to comment.