Add now/by-name endpoint

This commit is contained in:
norohind 2024-05-05 21:56:52 +03:00
parent 910d3579df
commit 9dc27157ff
3 changed files with 19 additions and 0 deletions

View File

@ -99,3 +99,7 @@ class SqliteModel:
squad[pretty_key] = squad.pop(key)
return squads
def name2tags(self, name: str) -> list[dict]:
v = self.get_db().execute(sqlite_sql_requests.name2tags, {'name': name}).fetchall()
return v

View File

@ -43,3 +43,12 @@ from squadrons_current_data
where tag like :tag
order by platform;
"""
name2tags = """select
platform,
squad_id,
updated as updated_at,
name,
tag
from squadrons_current_data
where lower(name) = lower(:name);"""

View File

@ -67,6 +67,11 @@ class SquadsInfoByTag:
resp.text = json.dumps(model_answer)
class SquadsName2Tags:
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response, name: str):
resp.content_type = falcon.MEDIA_JSON
resp.text = json.dumps(model.name2tags(name))
class AppFixedLogging(falcon.App):
def _python_error_handler(self, req: falcon.request.Request, resp: falcon.response.Response, error, params):
__exception__ = error
@ -79,6 +84,7 @@ application.add_route('/squads/now/by-tag/{details_type}/{tag}', SquadsInfoByTag
application.add_route('/api/squads/now/by-tag/{details_type}/{tag}', SquadsInfoByTag(is_pattern=False))
application.add_route('/api/squads/now/search/by-tag/{details_type}/{tag}', SquadsInfoByTag(is_pattern=True))
application.add_route('/api/squads/now/by-name/{name}', SquadsName2Tags())
if __name__ == '__main__':
import waitress