feat(api): adicionar endpoint para consulta de posição individual no ranking
- 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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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=["*"],
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user