feat: add route to convert aoid2aoguid

This commit is contained in:
Georg K
2020-12-24 04:51:59 +03:00
parent 966bec093f
commit 3b47bfd3a3
3 changed files with 31 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ class FiasFactory:
self.searcher = SphinxSearch(self.db)
self.expand_templ = template('aore/templates/postgre/expand_query.sql', aoid="//aoid")
self.normalize_templ = template('aore/templates/postgre/normalize_query.sql', aoid="//aoid")
self.convert_templ = template('aore/templates/postgre/convert_query.sql', aoid="//aoid")
self.gettext_templ = template('aore/templates/postgre/gettext_query.sql', aoid="//aoid")
# Проверка, что строка является действительым UUID v4
@@ -84,6 +85,27 @@ class FiasFactory:
else:
return rows[0]
# Преобразует AOID в AOGUID
def convert(self, aoid: str):
try:
self.__check_param(aoid, "uuid")
sql_query = self.convert_templ.replace("//aoid", aoid)
rows = self.db.get_rows(sql_query, True)
assert len(rows), "Record with this AOID not found in DB"
except Exception as err:
if BasicConfig.logging:
logging.error(traceback.format_exc())
if BasicConfig.debug_print:
traceback.print_exc()
return dict(error=str(err))
if len(rows) == 0:
return []
else:
return rows[0]
# Разворачивает AOID в представление (перед этим нормализует)
def expand(self, aoid_guid):
try: