feat: Sistema de Ranking de Consultores CAPES - versão inicial
Backend (FastAPI + DDD):
- Arquitetura DDD com camadas Domain, Application, Infrastructure, Interface
- Integração com Elasticsearch (ATUACAPES) para dados de consultores
- Integração com Oracle (SUCUPIRA_PAINEL) para coordenações PPG
- Cálculo dos 4 componentes de pontuação (A, B, C, D)
- Cache em memória para otimização de performance
- API REST com endpoints /ranking, /ranking/detalhado, /consultor/{id}
Frontend (React + Vite):
- Interface responsiva com cards expansíveis
- Visualização detalhada de pontuação por componente
- Filtro por quantidade de consultores (Top 10, 50, 100, etc)
Docker:
- docker-compose com shared_network externa
- Backend com Oracle Instant Client
- Frontend com Vite dev server
This commit is contained in:
0
backend/src/interface/api/__init__.py
Normal file
0
backend/src/interface/api/__init__.py
Normal file
50
backend/src/interface/api/app.py
Normal file
50
backend/src/interface/api/app.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from .routes import router
|
||||
from .config import settings
|
||||
from .dependencies import es_client, oracle_client
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
await es_client.connect()
|
||||
try:
|
||||
oracle_client.connect()
|
||||
except Exception as e:
|
||||
print(f"AVISO: Oracle não conectou: {e}. Sistema rodando sem Coordenação PPG.")
|
||||
yield
|
||||
await es_client.close()
|
||||
try:
|
||||
oracle_client.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Ranking de Consultores CAPES",
|
||||
description="Sistema de Ranking de Consultores CAPES baseado na Minuta Técnica",
|
||||
version="1.0.0",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.cors_origins_list,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {
|
||||
"message": "API Ranking CAPES",
|
||||
"version": "1.0.0",
|
||||
"docs": "/docs",
|
||||
"health": "/api/v1/health",
|
||||
}
|
||||
30
backend/src/interface/api/config.py
Normal file
30
backend/src/interface/api/config.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from typing import List
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
|
||||
|
||||
ES_URL: str = "http://localhost:9200"
|
||||
ES_INDEX: str = "atuacapes__1763197236"
|
||||
ES_USER: str = ""
|
||||
ES_PASSWORD: str = ""
|
||||
|
||||
ORACLE_USER: str
|
||||
ORACLE_PASSWORD: str
|
||||
ORACLE_DSN: str
|
||||
|
||||
API_HOST: str = "0.0.0.0"
|
||||
API_PORT: int = 8000
|
||||
API_RELOAD: bool = True
|
||||
|
||||
CORS_ORIGINS: str = "http://localhost:3000,http://localhost:5173"
|
||||
|
||||
LOG_LEVEL: str = "INFO"
|
||||
|
||||
@property
|
||||
def cors_origins_list(self) -> List[str]:
|
||||
return [origin.strip() for origin in self.CORS_ORIGINS.split(",")]
|
||||
|
||||
|
||||
settings = Settings()
|
||||
25
backend/src/interface/api/dependencies.py
Normal file
25
backend/src/interface/api/dependencies.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from ...infrastructure.elasticsearch.client import ElasticsearchClient
|
||||
from ...infrastructure.oracle.client import OracleClient
|
||||
from ...infrastructure.repositories.consultor_repository_impl import ConsultorRepositoryImpl
|
||||
from .config import settings
|
||||
|
||||
|
||||
es_client = ElasticsearchClient(
|
||||
url=settings.ES_URL,
|
||||
index=settings.ES_INDEX,
|
||||
user=settings.ES_USER,
|
||||
password=settings.ES_PASSWORD
|
||||
)
|
||||
|
||||
oracle_client = OracleClient(
|
||||
user=settings.ORACLE_USER, password=settings.ORACLE_PASSWORD, dsn=settings.ORACLE_DSN
|
||||
)
|
||||
|
||||
_repository: ConsultorRepositoryImpl = None
|
||||
|
||||
|
||||
def get_repository() -> ConsultorRepositoryImpl:
|
||||
global _repository
|
||||
if _repository is None:
|
||||
_repository = ConsultorRepositoryImpl(es_client=es_client, oracle_client=oracle_client)
|
||||
return _repository
|
||||
77
backend/src/interface/api/routes.py
Normal file
77
backend/src/interface/api/routes.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from typing import Optional
|
||||
|
||||
from ...application.use_cases.obter_ranking import ObterRankingUseCase
|
||||
from ...application.use_cases.obter_consultor import ObterConsultorUseCase
|
||||
from ...infrastructure.repositories.consultor_repository_impl import ConsultorRepositoryImpl
|
||||
from ..schemas.consultor_schema import (
|
||||
RankingResponseSchema,
|
||||
RankingDetalhadoResponseSchema,
|
||||
ConsultorDetalhadoSchema,
|
||||
ConsultorResumoSchema,
|
||||
)
|
||||
from .dependencies import get_repository
|
||||
|
||||
router = APIRouter(prefix="/api/v1", tags=["ranking"])
|
||||
|
||||
|
||||
@router.get("/ranking", response_model=RankingResponseSchema)
|
||||
async def obter_ranking(
|
||||
limite: int = Query(default=100, ge=1, le=1000, description="Limite de consultores"),
|
||||
offset: int = Query(default=0, ge=0, description="Offset para paginação"),
|
||||
componente: Optional[str] = Query(
|
||||
default=None, description="Filtrar por componente (a, b, c, d)"
|
||||
),
|
||||
repository: ConsultorRepositoryImpl = Depends(get_repository),
|
||||
):
|
||||
use_case = ObterRankingUseCase(repository=repository)
|
||||
consultores_dto = await use_case.executar(limite=limite, componente=componente)
|
||||
|
||||
total = await repository.contar_total()
|
||||
|
||||
consultores_schema = [
|
||||
ConsultorResumoSchema(**vars(dto)) for dto in consultores_dto
|
||||
]
|
||||
|
||||
return RankingResponseSchema(
|
||||
total=total, limite=limite, offset=offset, consultores=consultores_schema
|
||||
)
|
||||
|
||||
|
||||
@router.get("/ranking/detalhado", response_model=RankingDetalhadoResponseSchema)
|
||||
async def obter_ranking_detalhado(
|
||||
limite: int = Query(default=100, ge=1, le=1000, description="Limite de consultores"),
|
||||
componente: Optional[str] = Query(
|
||||
default=None, description="Filtrar por componente (a, b, c, d)"
|
||||
),
|
||||
repository: ConsultorRepositoryImpl = Depends(get_repository),
|
||||
):
|
||||
use_case = ObterRankingUseCase(repository=repository)
|
||||
consultores_dto = await use_case.executar_detalhado(limite=limite, componente=componente)
|
||||
|
||||
total = await repository.contar_total()
|
||||
|
||||
consultores_schema = [
|
||||
ConsultorDetalhadoSchema(**dto.to_dict()) for dto in consultores_dto
|
||||
]
|
||||
|
||||
return RankingDetalhadoResponseSchema(total=total, limite=limite, consultores=consultores_schema)
|
||||
|
||||
|
||||
@router.get("/consultor/{id_pessoa}", response_model=ConsultorDetalhadoSchema)
|
||||
async def obter_consultor(
|
||||
id_pessoa: int,
|
||||
repository: ConsultorRepositoryImpl = Depends(get_repository),
|
||||
):
|
||||
use_case = ObterConsultorUseCase(repository=repository)
|
||||
consultor = await use_case.executar(id_pessoa=id_pessoa)
|
||||
|
||||
if not consultor:
|
||||
raise HTTPException(status_code=404, detail=f"Consultor {id_pessoa} não encontrado")
|
||||
|
||||
return consultor
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health_check():
|
||||
return {"status": "ok", "message": "API Ranking CAPES funcionando"}
|
||||
Reference in New Issue
Block a user