39 lines
No EOL
1.3 KiB
Python
39 lines
No EOL
1.3 KiB
Python
from fastapi import HTTPException, status
|
|
from packages.v1.administrativo.actions.client.client_index_action import IndexAction
|
|
from typing import Tuple, List, Dict, Any
|
|
|
|
|
|
class IndexService:
|
|
"""
|
|
Service responsável por orquestrar a listagem (indexação) de todos
|
|
os clientes, delegando a busca para a Action correspondente.
|
|
"""
|
|
|
|
# O método execute agora recebe 'first' e 'skip'
|
|
def execute(self, first: int, skip: int) -> Tuple[List[Dict[str, Any]], int]:
|
|
|
|
"""
|
|
Executa o serviço de listagem de clientes.
|
|
|
|
:return: Lista de registros de clientes.
|
|
"""
|
|
|
|
# Instânciamento de ação
|
|
index_action = IndexAction()
|
|
|
|
# Executa a busca de todos os logs com paginação
|
|
data, total_records = index_action.execute(first, skip)
|
|
|
|
# Executa a busca de todos os clientes (a Action/Repository fará a busca, potencialmente com paginação)
|
|
data = index_action.execute()
|
|
|
|
# Verifica se foram localizados registros
|
|
if not data:
|
|
# Retorna uma exceção
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail='Não foi possível localizar os clientes'
|
|
)
|
|
|
|
# Retorna as informações localizadas
|
|
return data, total_records |