From 7c0631b6f3dea6a57767abd5e55329475a71d184 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 19 Nov 2024 20:36:22 -0300 Subject: [PATCH] =?UTF-8?q?atualiza=C3=A7=C3=A3o=20de=20filtros=20e=20rota?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/controllers/schemas/ProjetosRequestSchema.ts | 1 + backend/src/database/fetchAPI.ts | 4 ++-- .../src/repositories/prisma/PrismaProjetosRepository.ts | 6 ++++++ backend/src/repositories/projetoRepository.ts | 7 ++++++- backend/src/routes/routes.ts | 4 ++-- backend/src/server.ts | 2 +- backend/src/use-cases/ProjetosService.ts | 6 ++++-- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/backend/src/controllers/schemas/ProjetosRequestSchema.ts b/backend/src/controllers/schemas/ProjetosRequestSchema.ts index f02a3981..7e5e5a8e 100644 --- a/backend/src/controllers/schemas/ProjetosRequestSchema.ts +++ b/backend/src/controllers/schemas/ProjetosRequestSchema.ts @@ -3,6 +3,7 @@ import z from "zod"; export const GetProjetosRequestSchema = z.object({ page: z.string().optional(), pageSize: z.string().optional(), + natureza: z.string().optional(), situacao: z.string().optional(), uf: z.string().optional(), sortBy: z.enum(['situacao', 'uf', 'createdAt']).optional(), diff --git a/backend/src/database/fetchAPI.ts b/backend/src/database/fetchAPI.ts index 0ada31da..d7e5dc01 100644 --- a/backend/src/database/fetchAPI.ts +++ b/backend/src/database/fetchAPI.ts @@ -2,8 +2,8 @@ import axios from "axios"; import { prisma } from "@/database"; async function fetchAndSaveProjects() { - let pagina = 0; - const tamanhoDaPagina = 100; // Ajuste este valor conforme a capacidade da API + let pagina = 56; + const tamanhoDaPagina = 10; // Ajuste este valor conforme a capacidade da API let hasMoreData = true; let uf = "DF"; diff --git a/backend/src/repositories/prisma/PrismaProjetosRepository.ts b/backend/src/repositories/prisma/PrismaProjetosRepository.ts index 9c83077a..09db235f 100644 --- a/backend/src/repositories/prisma/PrismaProjetosRepository.ts +++ b/backend/src/repositories/prisma/PrismaProjetosRepository.ts @@ -15,6 +15,12 @@ export class PrismaProjetosRepository implements ProjetosRepository { equals: params.where?.uf?.equals, mode: params.where?.uf?.mode }, + natureza: { + contains: params.where?.natureza?.like, + equals: params.where?.natureza?.equals, + mode: params.where?.natureza?.mode + } + } const projetos = await prisma.projeto.findMany({ diff --git a/backend/src/repositories/projetoRepository.ts b/backend/src/repositories/projetoRepository.ts index 0ed195ae..c9f91ece 100644 --- a/backend/src/repositories/projetoRepository.ts +++ b/backend/src/repositories/projetoRepository.ts @@ -11,11 +11,16 @@ export interface ProjetoWhereParams { equals?: string; mode?: "default" | "insensitive" } + natureza?: { + like: string; + equals?: string; + mode?: "default" | "insensitive" + } } export interface FindProjetosParams { where?: ProjetoWhereParams - sortBy?: "situacao" | "uf" | "createdAt" + sortBy?: "natureza"| "situacao" | "uf" | "createdAt" order?: "asc" | "desc" limit?: number offset?: number diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index cd388a65..2b6c57ee 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -3,7 +3,7 @@ import { Router } from "express"; const router = Router() -router.get('/projects', projetosController.index) -router.get('/projects/:id', projetosController.show) +router.get('/projeto-investimento', projetosController.index) +router.get('/projeto-investimento/:id', projetosController.show) export { router } \ No newline at end of file diff --git a/backend/src/server.ts b/backend/src/server.ts index f6649dc3..3685f722 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -8,7 +8,7 @@ const app = express(); app.use(cors()); app.use(express.json()); -app.use('/api', router) +app.use('/', router) app.use(errorHandling); const PORT = process.env.PORT || 3333; diff --git a/backend/src/use-cases/ProjetosService.ts b/backend/src/use-cases/ProjetosService.ts index fe99f592..db609762 100644 --- a/backend/src/use-cases/ProjetosService.ts +++ b/backend/src/use-cases/ProjetosService.ts @@ -4,9 +4,10 @@ import { ProjetosRepository, ProjetoWhereParams } from "@/repositories/projetoRe interface GetProjetosWithPaginationParams { page?: number pageSize?: number + natureza?: string situacao?: string uf?: string - sortBy?: "situacao" | "uf" | "createdAt" + sortBy?: "natureza" | "situacao" | "uf" | "createdAt" order?: "asc" | "desc" } @@ -14,7 +15,7 @@ export class ProjetosService { constructor(private readonly projetosRepository: ProjetosRepository) {} async getAllProjetosPaginated(params: GetProjetosWithPaginationParams) { - const { situacao, uf, page = 1, pageSize = 10, sortBy, order } = params + const { natureza, situacao, uf, page = 1, pageSize = 10, sortBy, order } = params const limit = pageSize const offset = (page - 1) * limit @@ -22,6 +23,7 @@ export class ProjetosService { const where: ProjetoWhereParams = {} if (situacao) where.situacao = { like: situacao, mode: 'insensitive' } + if (natureza) where.natureza = { like: natureza, mode: 'insensitive' } if (uf) where.uf = { like: uf, mode: 'insensitive' } const projetos = await this.projetosRepository.find({