diff --git a/api/src/controllers/enrollmentController.ts b/api/src/adapters/controllers/enrollmentController.ts similarity index 74% rename from api/src/controllers/enrollmentController.ts rename to api/src/adapters/controllers/enrollmentController.ts index 874b461..bce1aa1 100644 --- a/api/src/controllers/enrollmentController.ts +++ b/api/src/adapters/controllers/enrollmentController.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express'; -import { MatriculasRepositoryPSQL } from '../database/psql/matriculasRepositoryPSQL'; -import { MatriculasService } from '../services/matriculasServices'; +import { EnrollmentService } from '../../application/services/enrollmentServices'; +import { EnrollmentRepositoryPSQL } from '../../infrastructure/database/psql/enrollmentRepositoryPSQL'; export const EnrollmentController = async (req: Request, res: Response) => { try { @@ -13,7 +13,7 @@ export const EnrollmentController = async (req: Request, res: Response) => { return res.status(400).json({ message: 'Municipio e Etapa são obrigatórios.' }); } - const service = new MatriculasService(new MatriculasRepositoryPSQL()); + const service = new EnrollmentService(new EnrollmentRepositoryPSQL()); const result = await service.execute({ municipio, etapa }); res.json(result); diff --git a/api/src/controllers/indicatorController.ts b/api/src/adapters/controllers/indicatorController.ts similarity index 76% rename from api/src/controllers/indicatorController.ts rename to api/src/adapters/controllers/indicatorController.ts index eb2eed1..b6b9447 100644 --- a/api/src/controllers/indicatorController.ts +++ b/api/src/adapters/controllers/indicatorController.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express'; -import { IndicadoresRepositoryPSQL } from '../database/psql/indicadoresRepositoryPSQL'; -import { IndicadoresService } from '../services/indicadoresServices'; +import { IndicatorService } from '../../application/services/indicatorServices'; +import { IndicatorRepositoryPSQL } from '../../infrastructure/database/psql/indicatorRepositoryPSQL'; export const IndicatorController = async (req: Request, res: Response) => { try { @@ -21,7 +21,7 @@ export const IndicatorController = async (req: Request, res: Response) => { .json({ message: 'Indicador, Etapa e Município são obrigatórios.' }); } - const service = new IndicadoresService(new IndicadoresRepositoryPSQL()); + const service = new IndicatorService(new IndicatorRepositoryPSQL()); const result = await service.execute({ indicador, etapa, municipio }); res.json(result); diff --git a/api/src/controllers/rankingController.ts b/api/src/adapters/controllers/rankingController.ts similarity index 81% rename from api/src/controllers/rankingController.ts rename to api/src/adapters/controllers/rankingController.ts index e818fc0..0eae93f 100644 --- a/api/src/controllers/rankingController.ts +++ b/api/src/adapters/controllers/rankingController.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express'; -import { RankingRepositoryPSQL } from '../database/psql/rankingRepositoryPSQL'; -import { RankingService } from '../services/rankingServices'; +import { RankingRepositoryPSQL } from '../../infrastructure/database/psql/rankingRepositoryPSQL'; +import { RankingService } from '../../application/services/rankingServices'; export const RankingController = async (req: Request, res: Response) => { try { diff --git a/api/src/adapters/repositories/enrollmentRepository.ts b/api/src/adapters/repositories/enrollmentRepository.ts new file mode 100644 index 0000000..d079c87 --- /dev/null +++ b/api/src/adapters/repositories/enrollmentRepository.ts @@ -0,0 +1,14 @@ +import { EnrollmentInput } from '../../application/services/enrollmentServices'; + +export type EnrollmentRepositoryOutput = { + ano: number; + raca: string; + rede: string; + etapa: string; + matricula: number; + municipio: string; +}; + +export abstract class EnrollmentRepository { + abstract fetch(input: EnrollmentInput): Promise; +} diff --git a/api/src/adapters/repositories/indicatorRepository.ts b/api/src/adapters/repositories/indicatorRepository.ts new file mode 100644 index 0000000..cb8e1af --- /dev/null +++ b/api/src/adapters/repositories/indicatorRepository.ts @@ -0,0 +1,15 @@ +import { IndicatorInput } from '../../application/services/indicatorServices'; + +export type IndicatorRepositoryOutput = { + ano: number; + rede: string; + etapa: string; + taxa_de_aprovacao: number; + taxa_de_reprovacao: number; + taxa_de_abandono: number; + municipio: string; +}; + +export abstract class IndicatorRepository { + abstract fetch(input: IndicatorInput): Promise; +} diff --git a/api/src/repositories/rankingRepository.ts b/api/src/adapters/repositories/rankingRepository.ts similarity index 74% rename from api/src/repositories/rankingRepository.ts rename to api/src/adapters/repositories/rankingRepository.ts index 92e7f77..29f6fcb 100644 --- a/api/src/repositories/rankingRepository.ts +++ b/api/src/adapters/repositories/rankingRepository.ts @@ -1,6 +1,5 @@ -import { RankingInput } from '../services/rankingServices'; +import { RankingInput } from '../../application/services/rankingServices'; -// output vindo do banco de dados export type RankingRepositoryOutput = { ano: number; raca: string; diff --git a/api/src/services/matriculasService.spec.ts b/api/src/application/services/enrollmentService.spec.ts similarity index 63% rename from api/src/services/matriculasService.spec.ts rename to api/src/application/services/enrollmentService.spec.ts index 7a959ca..521cdd6 100644 --- a/api/src/services/matriculasService.spec.ts +++ b/api/src/application/services/enrollmentService.spec.ts @@ -1,46 +1,46 @@ import { describe, expect, test } from 'vitest'; -import { genericData } from '../database/memory/data/matriculasMemoryData'; -import { MatriculasRepositoryMemory } from '../database/memory/matriculasRepositoryMemory'; -import { MatriculasInput, MatriculasService } from './matriculasServices'; +import { genericData } from '../../infrastructure/database/memory/data/enrollmentMemoryData'; +import { EnrollmentRepositoryMemory } from '../../infrastructure/database/memory/enrollmentRepositoryMemory'; +import { EnrollmentInput, EnrollmentService } from './enrollmentServices'; -describe('Matriculas Service', () => { - const matriculaRepository = new MatriculasRepositoryMemory(); - const matriculasService = new MatriculasService(matriculaRepository); +describe('Enrollment Service', () => { + const enrollmentRepository = new EnrollmentRepositoryMemory(); + const enrollmentService = new EnrollmentService(enrollmentRepository); - matriculaRepository.DATA_IN_MEMORY = genericData.map((item) => ({ + enrollmentRepository.DATA_IN_MEMORY = genericData.map((item) => ({ ...item, municipio: item.municipio.toString(), })); - const input: MatriculasInput = { + const input: EnrollmentInput = { etapa: 'EM', municipio: '3106200', }; test('should return categories length with success', async () => { - const output = await matriculasService.execute(input); + const output = await enrollmentService.execute(input); expect(output.categories).toHaveLength(8); }); test('should return first categorie with success', async () => { - const output = await matriculasService.execute(input); + const output = await enrollmentService.execute(input); expect(output.categories[0]).toEqual('2020 Pública'); }); test('should return second categorie with success', async () => { - const output = await matriculasService.execute(input); + const output = await enrollmentService.execute(input); expect(output.categories[1]).toEqual('2020 Privada'); }); test('should return series length with success', async () => { - const output = await matriculasService.execute(input); + const output = await enrollmentService.execute(input); expect(output.series).toHaveLength(2); }); test('should return an Error when not exists register with etapa filter', async () => { const incorrectEtapaInput = { ...input, etapa: 'Ensino' }; - await expect(matriculasService.execute(incorrectEtapaInput)).rejects.toThrowError( + await expect(enrollmentService.execute(incorrectEtapaInput)).rejects.toThrowError( 'Nenhum dado foi encontrado para estes filtros.', ); }); @@ -48,16 +48,16 @@ describe('Matriculas Service', () => { test('should return an Error when not exists register with municipio filter', async () => { const incorrectMunicipioInput = { ...input, municipio: 'BH' }; - await expect(matriculasService.execute(incorrectMunicipioInput)).rejects.toThrowError( + await expect(enrollmentService.execute(incorrectMunicipioInput)).rejects.toThrowError( 'Nenhum dado foi encontrado para estes filtros.', ); }); test('should return data in order', async () => { - matriculaRepository.DATA_IN_MEMORY = genericData.map((item) => ({ + enrollmentRepository.DATA_IN_MEMORY = genericData.map((item) => ({ ...item, municipio: item.municipio.toString(), })); - const response = await matriculasService.execute(input); + const response = await enrollmentService.execute(input); expect(response.series[0].name).toEqual('Pretos/Pardos'); expect(response.series[0].data).toEqual([0, 0, 0, 0, 85, 21, 100, 28]); expect(response.series[1].name).toEqual('Brancos'); diff --git a/api/src/services/matriculasServices.ts b/api/src/application/services/enrollmentServices.ts similarity index 68% rename from api/src/services/matriculasServices.ts rename to api/src/application/services/enrollmentServices.ts index d11291c..9520ff4 100644 --- a/api/src/services/matriculasServices.ts +++ b/api/src/application/services/enrollmentServices.ts @@ -1,6 +1,6 @@ -import { MatriculasRepository } from '../repositories/matriculasRepository'; +import { EnrollmentRepository } from '../../adapters/repositories/enrollmentRepository'; -export type MatriculasInput = { +export type EnrollmentInput = { municipio: string; etapa: string; }; @@ -13,11 +13,11 @@ type Output = { categories: string[]; }; -export class MatriculasService { - constructor(private matriculasRepository: MatriculasRepository) {} +export class EnrollmentService { + constructor(private enrollmentRepository: EnrollmentRepository) {} - async execute(input: MatriculasInput): Promise { - const data = await this.matriculasRepository.fetch(input); + async execute(input: EnrollmentInput): Promise { + const data = await this.enrollmentRepository.fetch(input); if (!data || data.length === 0) { throw new Error('Nenhum dado foi encontrado para estes filtros.'); @@ -59,15 +59,6 @@ export class MatriculasService { } }); - // REMOVE CATEGORIAS VAZIAS - // for (let i = categories.length - 1; i >= 0; i--) { - // if (newData['Pretos/Pardos'][i] <= 0 && newData.Brancos[i] <= 0) { - // newData['Pretos/Pardos'].splice(i, 1); - // newData.Brancos.splice(i, 1); - // categories.splice(i, 1); - // } - // } - const series = Object.entries(newData).map(([name, data]) => ({ name, data, diff --git a/api/src/services/indicadoresService.spec.ts b/api/src/application/services/indicatorService.spec.ts similarity index 56% rename from api/src/services/indicadoresService.spec.ts rename to api/src/application/services/indicatorService.spec.ts index 040e381..bb47dd9 100644 --- a/api/src/services/indicadoresService.spec.ts +++ b/api/src/application/services/indicatorService.spec.ts @@ -1,45 +1,45 @@ import { describe, expect, test } from 'vitest'; -import { genericData } from '../database/memory/data/indicadoresMemoryData'; -import { IndicadoresRepositoryMemory } from '../database/memory/indicadoresRepositoryMemory'; -import { IndicadoresInput, IndicadoresService } from './indicadoresServices'; +import { genericData } from '../../infrastructure/database/memory/data/indicatorMemoryData'; +import { IndicatorRepositoryMemory } from '../../infrastructure/database/memory/indicatorRepositoryMemory'; +import { IndicatorInput, IndicatorService } from './indicatorServices'; -describe('Indicadores Service', () => { - const indicadoresRepository = new IndicadoresRepositoryMemory(); - const indicadoresService = new IndicadoresService(indicadoresRepository); +describe('Indicator Service', () => { + const indicatorRepository = new IndicatorRepositoryMemory(); + const indicatorService = new IndicatorService(indicatorRepository); - indicadoresRepository.DATA_IN_MEMORY = genericData.map((item) => ({ + indicatorRepository.DATA_IN_MEMORY = genericData.map((item) => ({ ...item, municipio: item.municipio.toString(), })); - const input: IndicadoresInput = { + const input: IndicatorInput = { indicador: 'taxa_de_aprovacao', etapa: 'EF2', municipio: '3101102', }; test('should return categories length with success', async () => { - const output = await indicadoresService.execute(input); + const output = await indicatorService.execute(input); expect(output.categories).toHaveLength(4); }); test('should return first category with success', async () => { - const output = await indicadoresService.execute(input); + const output = await indicatorService.execute(input); expect(output.categories[0]).toEqual(2020); }); test('should return last categorie with success', async () => { - const output = await indicadoresService.execute(input); + const output = await indicatorService.execute(input); expect(output.categories[3]).toEqual(2023); }); test('should return series length with success', async () => { - const output = await indicadoresService.execute(input); + const output = await indicatorService.execute(input); expect(output.series).toHaveLength(2); }); test('should return first series with success', async () => { - const output = await indicadoresService.execute(input); + const output = await indicatorService.execute(input); expect(output.series[0].name).toEqual('Pública'); expect(output.series[0].data).toHaveLength(4); expect(output.series[0].data[0]).toEqual(97.9); @@ -47,7 +47,7 @@ describe('Indicadores Service', () => { }); test('should return second series with success', async () => { - const output = await indicadoresService.execute(input); + const output = await indicatorService.execute(input); expect(output.series[1].name).toEqual('Privada'); expect(output.series[1].data).toHaveLength(4); expect(output.series[1].data[0]).toEqual(100); @@ -55,9 +55,12 @@ describe('Indicadores Service', () => { }); test('should return an Error when not exists data with municipio filter', async () => { - const incorrectIndicadorInput = { ...input, municipio: 'Onde Judas perdeu as botas' }; + const incorrectIndicadorInput = { + ...input, + municipio: 'Onde Judas perdeu as botas', + }; - await expect(indicadoresService.execute(incorrectIndicadorInput)).rejects.toThrow( + await expect(indicatorService.execute(incorrectIndicadorInput)).rejects.toThrow( 'Nenhum dado foi encontrado para estes filtros.', ); }); diff --git a/api/src/services/indicadoresServices.ts b/api/src/application/services/indicatorServices.ts similarity index 71% rename from api/src/services/indicadoresServices.ts rename to api/src/application/services/indicatorServices.ts index ae25ab6..44b6dfc 100644 --- a/api/src/services/indicadoresServices.ts +++ b/api/src/application/services/indicatorServices.ts @@ -1,6 +1,6 @@ -import { IndicadoresRepository } from '../repositories/indicadoresRepository'; +import { IndicatorRepository } from '../../adapters/repositories/indicatorRepository'; -export type IndicadoresInput = { +export type IndicatorInput = { indicador: string; etapa: string; municipio: string; @@ -14,11 +14,11 @@ type Output = { }[]; }; -export class IndicadoresService { - constructor(private indicadoresRepository: IndicadoresRepository) {} +export class IndicatorService { + constructor(private indicatorRepository: IndicatorRepository) {} - async execute(input: IndicadoresInput): Promise { - const data = await this.indicadoresRepository.fetch(input); + async execute(input: IndicatorInput): Promise { + const data = await this.indicatorRepository.fetch(input); if (!data || data.length === 0) { throw new Error('Nenhum dado foi encontrado para estes filtros.'); @@ -30,17 +30,14 @@ export class IndicadoresService { }; const categories: number[] = []; - // Definindo os anos esperados const anos = [2020, 2021, 2022, 2023]; - // Criando combinações de ano anos.forEach((ano) => { categories.push(ano); newData.Pública.push(0); newData.Privada.push(0); }); - // Atualizando dados de indicadores data.forEach((entry: { [key: string]: any }) => { const index = categories.indexOf(entry.ano); diff --git a/api/src/services/rankingServices.spec.ts b/api/src/application/services/rankingServices.spec.ts similarity index 85% rename from api/src/services/rankingServices.spec.ts rename to api/src/application/services/rankingServices.spec.ts index 7675e3a..24bed9e 100644 --- a/api/src/services/rankingServices.spec.ts +++ b/api/src/application/services/rankingServices.spec.ts @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, test } from 'vitest'; -import { rankingData } from '../database/memory/data/rankingMemoryData'; -import { RankingRepositoryMemory } from '../database/memory/rankingRepositoryMemory'; +import { genericData } from '../../infrastructure/database/memory/data/rankingMemoryData'; +import { RankingRepositoryMemory } from '../../infrastructure/database/memory/rankingRepositoryMemory'; import { RankingInput, RankingService } from './rankingServices'; describe('Ranking Service', () => { @@ -10,7 +10,7 @@ describe('Ranking Service', () => { beforeEach(() => { rankingRepository = new RankingRepositoryMemory(); rankingService = new RankingService(rankingRepository); - rankingRepository.DATA_IN_MEMORY = rankingData; // Reset data before each test + rankingRepository.DATA_IN_MEMORY = genericData; }); const input: RankingInput = { diff --git a/api/src/services/rankingServices.ts b/api/src/application/services/rankingServices.ts similarity index 87% rename from api/src/services/rankingServices.ts rename to api/src/application/services/rankingServices.ts index 982dd69..c60e6df 100644 --- a/api/src/services/rankingServices.ts +++ b/api/src/application/services/rankingServices.ts @@ -1,4 +1,4 @@ -import { RankingRepository } from '../repositories/rankingRepository'; +import { RankingRepository } from '../../adapters/repositories/rankingRepository'; export type RankingInput = { ano: number; @@ -6,8 +6,8 @@ export type RankingInput = { }; type Output = { - name: string; // Nome do município - value: number; // Módulo da diferença percentual entre rede pública e privada + name: string; + value: number; }[]; export class RankingService { @@ -66,7 +66,6 @@ export class RankingService { const totalPrivada = newData[municipio].pretoPrivada + newData[municipio].brancoPrivada; - // Exclui o município se qualquer um dos valores totais for inferior a 10 if (totalPublica < 10 || totalPrivada < 10) { delete newData[municipio]; return null; @@ -85,7 +84,7 @@ export class RankingService { value: parseFloat(diferencaPorcentagem.toFixed(2)), }; }) - .filter((item) => item !== null); // Filtra os municípios que foram excluídos + .filter((item) => item !== null); return response; } diff --git a/api/src/database/memory/indicadoresRepositoryMemory.ts b/api/src/database/memory/indicadoresRepositoryMemory.ts deleted file mode 100644 index 76fe364..0000000 --- a/api/src/database/memory/indicadoresRepositoryMemory.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { - IndicadoresRepository, - IndicadoresRepositoryOutput, -} from '../../repositories/indicadoresRepository'; -import { IndicadoresInput } from '../../services/indicadoresServices'; - -export class IndicadoresRepositoryMemory extends IndicadoresRepository { - public DATA_IN_MEMORY: IndicadoresRepositoryOutput[] = []; - - async fetch(input: IndicadoresInput): Promise { - const { municipio, etapa } = input; - const response = this.DATA_IN_MEMORY.filter( - (item) => item.etapa === etapa && item.municipio === municipio, - ); - return response; - } -} diff --git a/api/src/database/memory/matriculasRepositoryMemory.ts b/api/src/database/memory/matriculasRepositoryMemory.ts deleted file mode 100644 index a008706..0000000 --- a/api/src/database/memory/matriculasRepositoryMemory.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { - MatriculasRepository, - MatriculasRepositoryOutput, -} from '../../repositories/matriculasRepository'; -import { MatriculasInput } from '../../services/matriculasServices'; - -export class MatriculasRepositoryMemory extends MatriculasRepository { - public DATA_IN_MEMORY: MatriculasRepositoryOutput[] = []; - - async fetch(input: MatriculasInput): Promise { - const { municipio, etapa } = input; - const response = this.DATA_IN_MEMORY.filter( - (item) => item.etapa === etapa && item.municipio === municipio, - ); - return response; - } -} diff --git a/api/src/index.ts b/api/src/index.ts index 0ab9a3e..0b685fa 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -4,9 +4,9 @@ import { config } from 'dotenv'; import express, { Request, Response } from 'express'; import swaggerJsdoc from 'swagger-jsdoc'; import swaggerUi from 'swagger-ui-express'; -import enrollmentRoute from './routes/enrollmentRoute'; -import indicatorRoute from './routes/indicatorRoute'; -import rankingRoute from './routes/rankingRoute'; +import enrollmentRoute from './infrastructure/routes/enrollmentRoute'; +import indicatorRoute from './infrastructure/routes/indicatorRoute'; +import rankingRoute from './infrastructure/routes/rankingRoute'; import { options } from './swaggerConfig'; config(); diff --git a/api/src/database/memory/data/matriculasMemoryData.ts b/api/src/infrastructure/database/memory/data/enrollmentMemoryData.ts similarity index 100% rename from api/src/database/memory/data/matriculasMemoryData.ts rename to api/src/infrastructure/database/memory/data/enrollmentMemoryData.ts diff --git a/api/src/database/memory/data/indicadoresMemoryData.ts b/api/src/infrastructure/database/memory/data/indicatorMemoryData.ts similarity index 100% rename from api/src/database/memory/data/indicadoresMemoryData.ts rename to api/src/infrastructure/database/memory/data/indicatorMemoryData.ts diff --git a/api/src/database/memory/data/rankingMemoryData.ts b/api/src/infrastructure/database/memory/data/rankingMemoryData.ts similarity index 99% rename from api/src/database/memory/data/rankingMemoryData.ts rename to api/src/infrastructure/database/memory/data/rankingMemoryData.ts index b1ffed0..63c72ab 100644 --- a/api/src/database/memory/data/rankingMemoryData.ts +++ b/api/src/infrastructure/database/memory/data/rankingMemoryData.ts @@ -1,4 +1,4 @@ -export const rankingData = [ +export const genericData = [ { ano: 2020, raca: 'Branca', diff --git a/api/src/infrastructure/database/memory/enrollmentRepositoryMemory.ts b/api/src/infrastructure/database/memory/enrollmentRepositoryMemory.ts new file mode 100644 index 0000000..83ccec4 --- /dev/null +++ b/api/src/infrastructure/database/memory/enrollmentRepositoryMemory.ts @@ -0,0 +1,17 @@ +import { + EnrollmentRepository, + EnrollmentRepositoryOutput, +} from '../../../adapters/repositories/enrollmentRepository'; +import { EnrollmentInput } from '../../../application/services/enrollmentServices'; + +export class EnrollmentRepositoryMemory extends EnrollmentRepository { + public DATA_IN_MEMORY: EnrollmentRepositoryOutput[] = []; + + async fetch(input: EnrollmentInput): Promise { + const { municipio, etapa } = input; + const response = this.DATA_IN_MEMORY.filter( + (item) => item.etapa === etapa && item.municipio === municipio, + ); + return response; + } +} diff --git a/api/src/infrastructure/database/memory/indicatorRepositoryMemory.ts b/api/src/infrastructure/database/memory/indicatorRepositoryMemory.ts new file mode 100644 index 0000000..02f3602 --- /dev/null +++ b/api/src/infrastructure/database/memory/indicatorRepositoryMemory.ts @@ -0,0 +1,17 @@ +import { + IndicatorRepository, + IndicatorRepositoryOutput, +} from '../../../adapters/repositories/indicatorRepository'; +import { IndicatorInput } from '../../../application/services/indicatorServices'; + +export class IndicatorRepositoryMemory extends IndicatorRepository { + public DATA_IN_MEMORY: IndicatorRepositoryOutput[] = []; + + async fetch(input: IndicatorInput): Promise { + const { municipio, etapa } = input; + const response = this.DATA_IN_MEMORY.filter( + (item) => item.etapa === etapa && item.municipio === municipio, + ); + return response; + } +} diff --git a/api/src/database/memory/rankingRepositoryMemory.ts b/api/src/infrastructure/database/memory/rankingRepositoryMemory.ts similarity index 72% rename from api/src/database/memory/rankingRepositoryMemory.ts rename to api/src/infrastructure/database/memory/rankingRepositoryMemory.ts index 7cd1f5c..16b9449 100644 --- a/api/src/database/memory/rankingRepositoryMemory.ts +++ b/api/src/infrastructure/database/memory/rankingRepositoryMemory.ts @@ -1,12 +1,11 @@ import { RankingRepository, RankingRepositoryOutput, -} from '../../repositories/rankingRepository'; -import { RankingInput } from '../../services/rankingServices'; +} from '../../../adapters/repositories/rankingRepository'; +import { RankingInput } from '../../../application/services/rankingServices'; export class RankingRepositoryMemory extends RankingRepository { public DATA_IN_MEMORY: RankingRepositoryOutput[] = []; - // filtrando os dados de acordo com a etapa e ano async fetch(input: RankingInput): Promise { const { ano, etapa } = input; const response = this.DATA_IN_MEMORY.filter( diff --git a/api/src/database/psql/matriculasRepositoryPSQL.ts b/api/src/infrastructure/database/psql/enrollmentRepositoryPSQL.ts similarity index 55% rename from api/src/database/psql/matriculasRepositoryPSQL.ts rename to api/src/infrastructure/database/psql/enrollmentRepositoryPSQL.ts index 3718631..ce337e0 100644 --- a/api/src/database/psql/matriculasRepositoryPSQL.ts +++ b/api/src/infrastructure/database/psql/enrollmentRepositoryPSQL.ts @@ -1,12 +1,12 @@ -import { supabase } from '../..'; +import { supabase } from '../../..'; import { - MatriculasRepository, - MatriculasRepositoryOutput, -} from '../../repositories/matriculasRepository'; -import { MatriculasInput } from '../../services/matriculasServices'; + EnrollmentRepository, + EnrollmentRepositoryOutput, +} from '../../../adapters/repositories/enrollmentRepository'; +import { EnrollmentInput } from '../../../application/services/enrollmentServices'; -export class MatriculasRepositoryPSQL extends MatriculasRepository { - async fetch(input: MatriculasInput): Promise { +export class EnrollmentRepositoryPSQL extends EnrollmentRepository { + async fetch(input: EnrollmentInput): Promise { const { data, error } = await supabase .from('Filtro') .select( @@ -18,14 +18,13 @@ export class MatriculasRepositoryPSQL extends MatriculasRepository { Matricula( id, cor_raca, quantidade, dependencia_administrativa) `, ) - .eq('municipio_id', Number(input.municipio)) // Filtrando por município - .eq('etapa_de_ensino', input.etapa) // Filtrando por etapa de ensino + .eq('municipio_id', Number(input.municipio)) + .eq('etapa_de_ensino', input.etapa) .gt('ano', 2019); if (error) { throw new Error(error.message); } else { - // Processar e retornar os dados no formato esperado - const result: MatriculasRepositoryOutput[] = data + const result: EnrollmentRepositoryOutput[] = data .map((filtro: any) => { return filtro.Matricula.map((mr: any) => ({ ano: filtro.ano, diff --git a/api/src/database/psql/indicadoresRepositoryPSQL.ts b/api/src/infrastructure/database/psql/indicatorRepositoryPSQL.ts similarity index 61% rename from api/src/database/psql/indicadoresRepositoryPSQL.ts rename to api/src/infrastructure/database/psql/indicatorRepositoryPSQL.ts index f20ce1a..a9eaa85 100644 --- a/api/src/database/psql/indicadoresRepositoryPSQL.ts +++ b/api/src/infrastructure/database/psql/indicatorRepositoryPSQL.ts @@ -1,12 +1,12 @@ -import { supabase } from '../..'; +import { supabase } from '../../..'; import { - IndicadoresRepository, - IndicadoresRepositoryOutput, -} from '../../repositories/indicadoresRepository'; -import { IndicadoresInput } from '../../services/indicadoresServices'; + IndicatorRepository, + IndicatorRepositoryOutput, +} from '../../../adapters/repositories/indicatorRepository'; +import { IndicatorInput } from '../../../application/services/indicatorServices'; -export class IndicadoresRepositoryPSQL extends IndicadoresRepository { - async fetch(input: IndicadoresInput): Promise { +export class IndicatorRepositoryPSQL extends IndicatorRepository { + async fetch(input: IndicatorInput): Promise { const { data, error } = await supabase .from('Filtro') .select( @@ -19,12 +19,11 @@ export class IndicadoresRepositoryPSQL extends IndicadoresRepository { `, ) .eq('municipio_id', Number(input.municipio)) - .eq('etapa_de_ensino', input.etapa); // Filtrando por município + .eq('etapa_de_ensino', input.etapa); if (error) { throw new Error(error.message); } else { - // Processar e retornar os dados no formato esperado - const result: IndicadoresRepositoryOutput[] = data + const result: IndicatorRepositoryOutput[] = data .map((filtro: any) => { return filtro.Indicador.map((mr: any) => ({ ano: filtro.ano, diff --git a/api/src/database/psql/rankingRepositoryPSQL.ts b/api/src/infrastructure/database/psql/rankingRepositoryPSQL.ts similarity index 91% rename from api/src/database/psql/rankingRepositoryPSQL.ts rename to api/src/infrastructure/database/psql/rankingRepositoryPSQL.ts index 8503f0d..ceaa46b 100644 --- a/api/src/database/psql/rankingRepositoryPSQL.ts +++ b/api/src/infrastructure/database/psql/rankingRepositoryPSQL.ts @@ -1,9 +1,9 @@ -import { supabase } from '../..'; +import { supabase } from '../../..'; import { RankingRepository, RankingRepositoryOutput, -} from '../../repositories/rankingRepository'; -import { RankingInput } from '../../services/rankingServices'; +} from '../../../adapters/repositories/rankingRepository'; +import { RankingInput } from '../../../application/services/rankingServices'; export class RankingRepositoryPSQL extends RankingRepository { async fetch(input: RankingInput): Promise { diff --git a/api/src/routes/enrollmentRoute.ts b/api/src/infrastructure/routes/enrollmentRoute.ts similarity index 93% rename from api/src/routes/enrollmentRoute.ts rename to api/src/infrastructure/routes/enrollmentRoute.ts index 9ef71b1..baa8046 100644 --- a/api/src/routes/enrollmentRoute.ts +++ b/api/src/infrastructure/routes/enrollmentRoute.ts @@ -1,5 +1,5 @@ import { Router } from 'express'; -import { EnrollmentController } from '../controllers/enrollmentController'; +import { EnrollmentController } from '../../adapters/controllers/enrollmentController'; const router = Router(); diff --git a/api/src/routes/indicatorRoute.ts b/api/src/infrastructure/routes/indicatorRoute.ts similarity index 95% rename from api/src/routes/indicatorRoute.ts rename to api/src/infrastructure/routes/indicatorRoute.ts index 60028c0..e26bb7c 100644 --- a/api/src/routes/indicatorRoute.ts +++ b/api/src/infrastructure/routes/indicatorRoute.ts @@ -1,5 +1,5 @@ import { Router } from 'express'; -import { IndicatorController } from '../controllers/indicatorController'; +import { IndicatorController } from '../../adapters/controllers/indicatorController'; const router = Router(); diff --git a/api/src/routes/rankingRoute.ts b/api/src/infrastructure/routes/rankingRoute.ts similarity index 92% rename from api/src/routes/rankingRoute.ts rename to api/src/infrastructure/routes/rankingRoute.ts index 8dd3fe9..a892819 100644 --- a/api/src/routes/rankingRoute.ts +++ b/api/src/infrastructure/routes/rankingRoute.ts @@ -1,5 +1,5 @@ import { Router } from 'express'; -import { RankingController } from '../controllers/rankingController'; +import { RankingController } from '../../adapters/controllers/rankingController'; const router = Router(); /** diff --git a/api/src/repositories/indicadoresRepository.ts b/api/src/repositories/indicadoresRepository.ts deleted file mode 100644 index 74be662..0000000 --- a/api/src/repositories/indicadoresRepository.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { IndicadoresInput } from '../services/indicadoresServices'; - -export type IndicadoresRepositoryOutput = { - ano: number; - rede: string; - etapa: string; - taxa_de_aprovacao: number; - taxa_de_reprovacao: number; - taxa_de_abandono: number; - municipio: string; -}; - -export abstract class IndicadoresRepository { - abstract fetch(input: IndicadoresInput): Promise; -} diff --git a/api/src/repositories/matriculasRepository.ts b/api/src/repositories/matriculasRepository.ts deleted file mode 100644 index ee0fc9c..0000000 --- a/api/src/repositories/matriculasRepository.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MatriculasInput } from '../services/matriculasServices'; - -export type MatriculasRepositoryOutput = { - ano: number; - raca: string; - rede: string; - etapa: string; - matricula: number; - municipio: string; -}; - -export abstract class MatriculasRepository { - abstract fetch(input: MatriculasInput): Promise; -} diff --git a/api/src/swaggerConfig.ts b/api/src/swaggerConfig.ts index c02f02c..1755192 100644 --- a/api/src/swaggerConfig.ts +++ b/api/src/swaggerConfig.ts @@ -17,5 +17,5 @@ const swaggerDefinition: SwaggerDefinition = { export const options = { swaggerDefinition, - apis: ['./api/src/routes/*.ts'], + apis: ['./api/src/infrastructure/routes/*.ts'], }; diff --git a/vitest.config.ts b/vitest.config.ts index 12b0643..c36ce3a 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ interopDefault: true, }, coverage: { - include: ['api/src/services'], + include: ['api/src/application/services'], provider: 'v8', }, },