Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat #61/implement indicadores #62

Merged
merged 10 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions api/src/controllers/indicatorController.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import { Request, Response } from 'express';
import { IndicadoresRepositoryPSQL } from '../database/psql/indicadoresRepositoryPSQL';
import { IndicadoresService } from '../services/indicadoresServices';

export const IndicatorController = async (req: Request, res: Response) => {
const { municipio, etapa, indicador, rede } = req.query;
console.log(
`Indicador Município: ${municipio} - Etapa: ${etapa} - Indicador: ${indicador} - Rede: ${rede}`,
);
try {
const { indicador, etapa, municipio } = req.query;

const response = {
categories: [2019, 2020, 2021, 2022, 2023],
series: [
{
name: 'Brancos',
data: [
Math.floor(Math.random() * 10001),
Math.floor(Math.random() * 10001),
Math.floor(Math.random() * 10001),
Math.floor(Math.random() * 10001),
Math.floor(Math.random() * 10001),
],
},
{
name: 'Pretos/Pardos',
data: [
Math.floor(Math.random() * 10001),
Math.floor(Math.random() * 10001),
Math.floor(Math.random() * 10001),
Math.floor(Math.random() * 10001),
Math.floor(Math.random() * 10001),
],
},
],
};
res.json(response);
if (
typeof indicador !== 'string' ||
typeof etapa !== 'string' ||
typeof municipio !== 'string'
) {
return res
.status(400)
.json({ message: 'Indicador, Etapa ou Município inválidos.' });
}
if (!indicador || !etapa || !municipio) {
return res
.status(400)
.json({ message: 'Indicador, Etapa e Município são obrigatórios.' });
}

const service = new IndicadoresService(new IndicadoresRepositoryPSQL());
const result = await service.execute({ indicador, etapa, municipio });

res.json(result);
} catch (error) {
console.error('Erro ao processar a solicitação:', error);
res.status(400).json({ message: (error as any).message });
}
};
Loading
Loading