From 94da1d736aa568654e091b04787952abc7573e2c Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Tue, 8 Oct 2024 11:38:08 -0300
Subject: [PATCH 1/7] [ADD] Trying to search for university in courseAggregate

---
 src/libs/routes_v1/courseAggregate.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js
index fdc6bd88..4fde328f 100644
--- a/src/libs/routes_v1/courseAggregate.js
+++ b/src/libs/routes_v1/courseAggregate.js
@@ -316,7 +316,7 @@ rqf.addField({
         field: 'cod_cine_area_detalhada'
     }
 }).addValue({
-    name: 'university',
+    name: 'universityLocalOffer',
     table: 'ies_ens_superior',
     tableField: ['cod_ies', 'nome_ies'],
     resultField: ['university_id', 'university_name'],
-- 
GitLab


From 87e65daa8fe9b31bc0254687bb848d9586667cff Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 9 Oct 2024 09:44:11 -0300
Subject: [PATCH 2/7] [ADD] Creating new route to list all the universities
 above 2020

---
 src/libs/routes_v1/api.js                    |  3 +
 src/libs/routes_v1/uniLocalOfferAggregate.js | 89 ++++++++++++++++++++
 2 files changed, 92 insertions(+)
 create mode 100644 src/libs/routes_v1/uniLocalOfferAggregate.js

diff --git a/src/libs/routes_v1/api.js b/src/libs/routes_v1/api.js
index 1abfe6f0..bffc8b5d 100644
--- a/src/libs/routes_v1/api.js
+++ b/src/libs/routes_v1/api.js
@@ -155,6 +155,8 @@ const federativeEntity = require(`${libs}/routes_v1/federativeEntity`);
 
 const email = require(`${libs}/routes_v1/email`);
 
+const uniLocalOfferAggregate = require(`${libs}/routes_v1/uniLocalOfferAggregate`)
+
 api.get('/', (req, res) => {
     res.json({ msg: 'SimCAQ API v1 is running' });
 });
@@ -220,6 +222,7 @@ api.use('/enrollmentAggregate', enrollmentAggregate);
 api.use('/employeesAggregate', employeesAggregate);
 api.use('/course_aggregate', courseAggregate);
 api.use('/federativeEntity', federativeEntity);
+api.use('/uni_offer_aggregate', uniLocalOfferAggregate);
 
 
 //Publication 
diff --git a/src/libs/routes_v1/uniLocalOfferAggregate.js b/src/libs/routes_v1/uniLocalOfferAggregate.js
new file mode 100644
index 00000000..bed9d5b0
--- /dev/null
+++ b/src/libs/routes_v1/uniLocalOfferAggregate.js
@@ -0,0 +1,89 @@
+/*
+Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+const express = require('express');
+
+const uniLocalOfferAggregateApp = express.Router();
+
+const libs = `${process.cwd()}/libs`;
+
+const query = require(`${libs}/middlewares/query`).query;
+
+const response = require(`${libs}/middlewares/response`);
+
+const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
+
+const config = require(`${libs}/config`); 
+
+const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
+
+let rqf = new ReqQueryFields();
+
+uniLocalOfferAggregateApp.use(cache('15 day'));
+
+rqf.addField({
+    name: 'filter',
+    field: false,
+    where: true
+}).addField({
+    name: 'dims',
+    field: true,
+    where: false
+}).addValue({
+    name: 'state',
+    table: 'estado',
+    tableField: ['id', 'nome'],
+    resultField: ['state_id', 'state_nome'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id',
+    },
+    join: {
+        primary: 'id',
+        foreign: 'cod_uf',
+        foreignTable: 'curso_superior_agregado'
+    }
+}).addValue({
+    name: 'city',
+    table: 'municipio',
+    tableField: ['id', 'nome'],
+    resultField: ['city_id', 'city_name'],
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id',
+        table: 'municipio'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'cod_mun',
+        foreignTable: 'curso_superior_agregado'
+    }
+});
+
+
+uniLocalOfferAggregateApp.get('/', (req, res, next) => {
+    req.sql.from('curso_superior_agregado')
+    .field('DISTINCT curso_superior_agregado.cod_ies', 'cod')
+    .field('ies_ens_superior.nome_ies', 'nome')
+    .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo')
+    next();
+}, query, response('uni_offer_aggregate'));
\ No newline at end of file
-- 
GitLab


From ef7e957c3587f170bf9496bc63446b4e837bf60d Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 9 Oct 2024 10:02:11 -0300
Subject: [PATCH 3/7] [ADD] Adding module.export to new route file

---
 src/libs/routes_v1/uniLocalOfferAggregate.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/libs/routes_v1/uniLocalOfferAggregate.js b/src/libs/routes_v1/uniLocalOfferAggregate.js
index bed9d5b0..184bc60d 100644
--- a/src/libs/routes_v1/uniLocalOfferAggregate.js
+++ b/src/libs/routes_v1/uniLocalOfferAggregate.js
@@ -79,11 +79,12 @@ rqf.addField({
     }
 });
 
-
 uniLocalOfferAggregateApp.get('/', (req, res, next) => {
     req.sql.from('curso_superior_agregado')
     .field('DISTINCT curso_superior_agregado.cod_ies', 'cod')
     .field('ies_ens_superior.nome_ies', 'nome')
     .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo')
     next();
-}, query, response('uni_offer_aggregate'));
\ No newline at end of file
+}, query, response('uni_offer_aggregate'));
+
+module.exports = uniLocalOfferAggregateApp;
\ No newline at end of file
-- 
GitLab


From cee0eee2ecda809fec64d0ff53d98d5b41168ed3 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 9 Oct 2024 10:59:32 -0300
Subject: [PATCH 4/7] [ADD] Adding rqf builders to the route, where it can
 build the query with filters/dims

---
 src/libs/routes_v1/uniLocalOfferAggregate.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libs/routes_v1/uniLocalOfferAggregate.js b/src/libs/routes_v1/uniLocalOfferAggregate.js
index 184bc60d..28f6abdf 100644
--- a/src/libs/routes_v1/uniLocalOfferAggregate.js
+++ b/src/libs/routes_v1/uniLocalOfferAggregate.js
@@ -79,11 +79,12 @@ rqf.addField({
     }
 });
 
-uniLocalOfferAggregateApp.get('/', (req, res, next) => {
+uniLocalOfferAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
     req.sql.from('curso_superior_agregado')
     .field('DISTINCT curso_superior_agregado.cod_ies', 'cod')
     .field('ies_ens_superior.nome_ies', 'nome')
     .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo')
+    .order('curso_superior_agregado.cod_ies')
     next();
 }, query, response('uni_offer_aggregate'));
 
-- 
GitLab


From bf7a6dacc8ef53beee68097bb935f0ff1c7f1a6f Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 9 Oct 2024 11:34:03 -0300
Subject: [PATCH 5/7] [ADD] Changing route return names

---
 src/libs/routes_v1/uniLocalOfferAggregate.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libs/routes_v1/uniLocalOfferAggregate.js b/src/libs/routes_v1/uniLocalOfferAggregate.js
index 28f6abdf..ab50ef37 100644
--- a/src/libs/routes_v1/uniLocalOfferAggregate.js
+++ b/src/libs/routes_v1/uniLocalOfferAggregate.js
@@ -81,8 +81,8 @@ rqf.addField({
 
 uniLocalOfferAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
     req.sql.from('curso_superior_agregado')
-    .field('DISTINCT curso_superior_agregado.cod_ies', 'cod')
-    .field('ies_ens_superior.nome_ies', 'nome')
+    .field('DISTINCT curso_superior_agregado.cod_ies', 'id')
+    .field('ies_ens_superior.nome_ies', 'name')
     .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo')
     .order('curso_superior_agregado.cod_ies')
     next();
-- 
GitLab


From e450bde4bff13edf286568c46f8a6e11860eaeb7 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 9 Oct 2024 11:55:54 -0300
Subject: [PATCH 6/7] [ADD] Adding new filters and new fields to query

---
 src/libs/routes_v1/uniLocalOfferAggregate.js | 33 ++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/libs/routes_v1/uniLocalOfferAggregate.js b/src/libs/routes_v1/uniLocalOfferAggregate.js
index ab50ef37..f50afff1 100644
--- a/src/libs/routes_v1/uniLocalOfferAggregate.js
+++ b/src/libs/routes_v1/uniLocalOfferAggregate.js
@@ -46,6 +46,36 @@ rqf.addField({
     name: 'dims',
     field: true,
     where: false
+}).addValue({
+    name: 'min_year',
+    table: 'curso_superior_agregado',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '>=',
+        type: 'integer',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'max_year',
+    table: 'curso_superior_agregado',
+    tableField: '',
+    resultField: 'year',
+    where: {
+        relation: '<=',
+        type: 'integer',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'region',
+    table: 'curso_superior_agregado',
+    tableField: 'cod_reg',
+    resultField: 'region_id',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'cod_reg'
+    }
 }).addValue({
     name: 'state',
     table: 'estado',
@@ -83,6 +113,9 @@ uniLocalOfferAggregateApp.get('/', rqf.parse(), rqf.build(), (req, res, next) =>
     req.sql.from('curso_superior_agregado')
     .field('DISTINCT curso_superior_agregado.cod_ies', 'id')
     .field('ies_ens_superior.nome_ies', 'name')
+    .field('curso_superior_agregado.cod_mun', 'city_id')
+    .field('curso_superior_agregado.cod_uf', 'state_id')
+    .field('curso_superior_agregado.cod_reg', 'region_id')
     .join('ies_ens_superior', null, 'curso_superior_agregado.cod_ies = ies_ens_superior.cod_ies and curso_superior_agregado.ano_censo = ies_ens_superior.ano_censo')
     .order('curso_superior_agregado.cod_ies')
     next();
-- 
GitLab


From 5b1b6c62867727ed78836b94b4f7fbc738d28e0e Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Wed, 9 Oct 2024 13:20:19 -0300
Subject: [PATCH 7/7] [FIX] Changing 'universityLocalOffer' filter to
 'uni_offer_aggregate' in courseAggregate route

---
 src/libs/routes_v1/courseAggregate.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/routes_v1/courseAggregate.js b/src/libs/routes_v1/courseAggregate.js
index 4fde328f..78ae89a7 100644
--- a/src/libs/routes_v1/courseAggregate.js
+++ b/src/libs/routes_v1/courseAggregate.js
@@ -316,7 +316,7 @@ rqf.addField({
         field: 'cod_cine_area_detalhada'
     }
 }).addValue({
-    name: 'universityLocalOffer',
+    name: 'uni_offer_aggregate',
     table: 'ies_ens_superior',
     tableField: ['cod_ies', 'nome_ies'],
     resultField: ['university_id', 'university_name'],
-- 
GitLab