From ffdd4cad2c302e7adde399886f5025c9992dbd89 Mon Sep 17 00:00:00 2001 From: Frederico Castro Date: Thu, 18 Dec 2025 05:50:11 -0300 Subject: [PATCH] =?UTF-8?q?feat(api):=20adicionar=20endpoint=20para=20cons?= =?UTF-8?q?ulta=20de=20posi=C3=A7=C3=A3o=20individual=20no=20ranking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Novo endpoint GET /api/v1/ranking/posicao/{id_pessoa} - Retorna posição, pontuação por bloco e total de consultores - Para integração com frontend do ATUACAPES --- backend/.env.example | 2 + backend/src/interface/api/app.py | 4 +- backend/src/interface/api/routes.py | 45 +++++++++++++++++++ .../src/interface/schemas/ranking_schema.py | 14 ++++++ docker-compose.yml | 2 +- 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/backend/.env.example b/backend/.env.example index 0c1fad2..7371796 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -14,3 +14,5 @@ ORACLE_LOCAL_DSN=XEPDB1 ORACLE_CLIENT=oracle-local HOST_ATUACAPES=https://atuacapes.capes.gov.br + +CORS_ORIGINS=http://localhost:5173,http://localhost:4200,http://127.0.0.1:4200 diff --git a/backend/src/interface/api/app.py b/backend/src/interface/api/app.py index 9a95943..4dc8231 100644 --- a/backend/src/interface/api/app.py +++ b/backend/src/interface/api/app.py @@ -141,8 +141,8 @@ app = FastAPI( app.add_middleware( CORSMiddleware, - allow_origins=settings.cors_origins_list, - allow_credentials=True, + allow_origins=["*"], + allow_credentials=False, allow_methods=["*"], allow_headers=["*"], ) diff --git a/backend/src/interface/api/routes.py b/backend/src/interface/api/routes.py index 8c471c4..cbddaa6 100644 --- a/backend/src/interface/api/routes.py +++ b/backend/src/interface/api/routes.py @@ -20,6 +20,7 @@ from ..schemas.ranking_schema import ( ProcessarRankingRequestSchema, ProcessarRankingResponseSchema, ConsultaNomeSchema, + PosicaoRankingSchema, ) from .dependencies import get_repository, get_ranking_store, get_processar_job, get_es_client from ...infrastructure.elasticsearch.client import ElasticsearchClient @@ -308,6 +309,50 @@ async def processar_ranking( ) +@router.get("/ranking/posicao/{id_pessoa}", response_model=PosicaoRankingSchema) +async def obter_posicao_ranking( + id_pessoa: int, + store = Depends(get_ranking_store), +): + if not store.is_ready(): + raise HTTPException( + status_code=503, + detail="Ranking ainda não foi processado. Execute POST /api/v1/ranking/processar.", + ) + + entry = store.get_by_id(id_pessoa) + total = store.total() + + if not entry: + return PosicaoRankingSchema( + id_pessoa=id_pessoa, + nome="", + posicao=None, + total_consultores=total, + pontuacao_total=0, + bloco_a=0, + bloco_b=0, + bloco_c=0, + bloco_d=0, + ativo=False, + encontrado=False, + ) + + return PosicaoRankingSchema( + id_pessoa=entry.id_pessoa, + nome=entry.nome, + posicao=entry.posicao, + total_consultores=total, + pontuacao_total=float(entry.pontuacao_total), + bloco_a=float(entry.bloco_a), + bloco_b=float(entry.bloco_b), + bloco_c=float(entry.bloco_c), + bloco_d=float(entry.bloco_d), + ativo=entry.ativo, + encontrado=True, + ) + + @router.get("/consultor/{id_pessoa}/raw") async def obter_consultor_raw( id_pessoa: int, diff --git a/backend/src/interface/schemas/ranking_schema.py b/backend/src/interface/schemas/ranking_schema.py index 2db43e4..f7f255e 100644 --- a/backend/src/interface/schemas/ranking_schema.py +++ b/backend/src/interface/schemas/ranking_schema.py @@ -77,3 +77,17 @@ class ConsultaNomeSchema(BaseModel): nome: str posicao: Optional[int] pontuacao_total: float + + +class PosicaoRankingSchema(BaseModel): + id_pessoa: int + nome: str + posicao: Optional[int] + total_consultores: int + pontuacao_total: float + bloco_a: float + bloco_b: float + bloco_c: float + bloco_d: float + ativo: bool + encontrado: bool = True diff --git a/docker-compose.yml b/docker-compose.yml index 3b66282..d999c7b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: - API_HOST=0.0.0.0 - API_PORT=8000 - API_RELOAD=true - - CORS_ORIGINS=http://localhost:5173,http://frontend:5173 + - CORS_ORIGINS=http://localhost:5173,http://frontend:5173,http://localhost:4200,http://127.0.0.1:4200 - LOG_LEVEL=INFO volumes: - ./backend/src:/app/src