Debug
This commit is contained in:
parent
bcb3df4422
commit
6704078e1f
1 changed files with 20 additions and 30 deletions
|
|
@ -1,53 +1,43 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from packages.v1.administrativo.schemas.log_schema import LogClientIdSchema
|
||||
|
||||
from typing import Dict, Any, Optional # Adicionado para clareza
|
||||
|
||||
class ShowDatabaseRepository(BaseRepository):
|
||||
"""
|
||||
Repositório responsável por buscar um registro único na tabela 'log'
|
||||
utilizando a chave primária 'log_id'.
|
||||
utilizando a chave primária 'log_id' e a estrutura de referência.
|
||||
"""
|
||||
|
||||
def execute(self, log_schema: LogClientIdSchema):
|
||||
"""
|
||||
Executa a busca de um log pelo seu ID.
|
||||
def execute(self, log_schema: LogClientIdSchema) -> Optional[Dict[str, Any]]:
|
||||
# 1. Busca do Log
|
||||
sql_log = """ SELECT * FROM log l WHERE l.client_id = :clientId ORDER BY l.log_id DESC LIMIT 1 """
|
||||
params = {'clientId': log_schema.client_id}
|
||||
log_database = self.fetch_one(sql_log, params)
|
||||
|
||||
:param log_schema: Schema contendo o log_id.
|
||||
:return: O registro de log encontrado ou None.
|
||||
"""
|
||||
|
||||
# Define a consulta sql. O SELECT * retorna todos os campos da DDL:
|
||||
# log_id, client_id, date_post, file.
|
||||
sql = """ SELECT * FROM log l WHERE l.client_id = :clientId ORDER BY l.log_id DESC LIMIT 1 """
|
||||
|
||||
# Preenchimento dos parâmetros SQL
|
||||
params = {
|
||||
'clientId': log_schema.client_id
|
||||
}
|
||||
|
||||
# Execução da instrução sql para buscar um único registro
|
||||
log_database = self.fetch_one(sql, params)
|
||||
|
||||
# Se não encontrar o log, retorna None para o Service lidar com o 404
|
||||
# Se não encontrar o log, retorna None
|
||||
if not log_database:
|
||||
return None
|
||||
return None
|
||||
|
||||
# 2. Busca da estrutura de referência (padrão)
|
||||
# Assumindo que a estrutura mais recente é a última inserida (ou a única)
|
||||
sql_standard_structure = """
|
||||
SELECT structure FROM firebird_schema LIMIT 1
|
||||
"""
|
||||
|
||||
# Execução para buscar a estrutura padrão (sem parâmetros)
|
||||
structure_database = self.fetch_one(sql_standard_structure, None)
|
||||
# Execução para buscar a estrutura padrão (retorna {'structure': 'string JSON'} ou None)
|
||||
structure_database_result = self.fetch_one(sql_standard_structure, None)
|
||||
|
||||
#print(structure_database)
|
||||
# Extrai a string JSON da chave 'structure'
|
||||
standard_structure_json_string = None
|
||||
if structure_database_result:
|
||||
standard_structure_json_string = structure_database_result.get("structure")
|
||||
|
||||
# 3. Combinação dos resultados
|
||||
# Adiciona a string JSON da estrutura padrão ao dicionário de dados do log
|
||||
data = {
|
||||
**log_database,
|
||||
"standard_structure_database": structure_database
|
||||
# Adicionamos a string JSON da estrutura no campo "standard_structure_json"
|
||||
"standard_structure_json": standard_structure_json_string
|
||||
}
|
||||
|
||||
return data
|
||||
print(standard_structure_json_string)
|
||||
|
||||
return data
|
||||
Loading…
Add table
Reference in a new issue