Skip to content

Commit

Permalink
Merge pull request #62 from ES2-UFPI/dev
Browse files Browse the repository at this point in the history
segunda release
  • Loading branch information
iuryFilho authored Jan 7, 2025
2 parents 160efff + c9979c7 commit e33d3cc
Show file tree
Hide file tree
Showing 47 changed files with 5,585 additions and 580 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: DEV - Start & Test (API)

on:
push:
branches: [ "dev", "main" ]
pull_request:
branches: [ "dev", "main" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Create .env file
working-directory: backend
run: |
echo "TYPE=${{ secrets.TYPE }}" > .env
echo "PROJECT_ID=${{ secrets.PROJECT_ID }}" >> .env
echo "PRIVATE_KEY_ID=${{ secrets.PRIVATE_KEY_ID }}" >> .env
echo 'PRIVATE_KEY="${{ secrets.PRIVATE_KEY }}"' >> .env
echo "CLIENT_EMAIL=${{ secrets.CLIENT_EMAIL }}" >> .env
echo "CLIENT_ID=${{ secrets.CLIENT_ID }}" >> .env
echo "AUTH_URI=${{ secrets.AUTH_URI }}" >> .env
echo "TOKEN_URI=${{ secrets.TOKEN_URI }}" >> .env
echo "AUTH_PROVIDER_X509_CERT_URL=${{ secrets.AUTH_PROVIDER_X509_CERT_URL }}" >> .env
echo "CLIENT_X509_CERT_URL=${{ secrets.CLIENT_X509_CERT_URL }}" >> .env
echo "UNIVERSE_DOMAIN=${{ secrets.UNIVERSE_DOMAIN }}" >> .env
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: backend/package-lock.json
- run: npm ci
working-directory: backend
- name: Start server
working-directory: backend
run: |
npm start &
SERVER_PID=$!
sleep 6
kill $SERVER_PID
- name: Run tests
working-directory: backend
run: npm test
28 changes: 28 additions & 0 deletions .github/workflows/front.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test (Front)

on:
push:
branches: [ "dev", "main" ]
pull_request:
branches: [ "dev", "main" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable

- name: Install dependencies
run: flutter pub get
working-directory: healthway_app

- name: Run tests
run: flutter test
working-directory: healthway_app
68 changes: 0 additions & 68 deletions app/lib/main.dart

This file was deleted.

24 changes: 18 additions & 6 deletions backend/controllers/alimentoController.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const db = require('../firebase-config');
const Alimento = require('../model/alimento');
const Alimento = require('../model/Alimento');

const alimentoController = {
//Criar um novo alimento
async create(req, res){
try {
const alimento = new Alimento(req.body);
await db.collection('alimento').add(alimento.toFirestore());
await db.collection('alimentos').add(alimento.toFirestore());
res.status(201).json({ message: 'Alimento criado com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
Expand All @@ -16,19 +16,31 @@ const alimentoController = {
//Obter todos os alimentos
async getAll(req, res){
try {
const snapshot = await db.collection('alimento').get();
const snapshot = await db.collection('alimentos').get();
const alimentos = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
res.status(200).json(alimentos);
} catch (error) {
res.status(500).json({ error: error.message });
}
},

// Obter alimentos por categoria
async getByCategory(req, res) {
try {
const { categoria } = req.params;
const snapshot = await db.collection('alimentos').where('Categoria', '==', categoria).get();
const alimentos = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
res.status(200).json(alimentos);
} catch (error) {
res.status(500).json({ error: error.message });
}
},

//Obter um alimento pelo ID
async getById(req, res){
try {
const { id } = req.params;
const doc = await db.collection('alimento').doc(id).get();
const doc = await db.collection('alimentos').doc(id).get();

if (!doc.exists) {
return res.status(404).json({ error: 'Alimento não encontrado.' });
Expand All @@ -46,7 +58,7 @@ const alimentoController = {
const { id } = req.params;
const alimento = new Alimento(req.body);

await db.collection('alimento').doc(id).update(alimento.toFirestore());
await db.collection('alimentos').doc(id).update(alimento.toFirestore());
res.status(200).json({ message: 'Alimento atualizado com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
Expand All @@ -57,7 +69,7 @@ const alimentoController = {
async delete(req, res){
try {
const { id } = req.params;
await db.collection('alimento').doc(id).delete();
await db.collection('alimentos').doc(id).delete();
res.status(200).json({ message: 'Alimento excluído com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
Expand Down
53 changes: 37 additions & 16 deletions backend/controllers/nutricionistaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,48 @@ const nutricionistaController = {
}
},

// Adicionar a função no controller
async getBySpecialty(req, res) {
try {
const { specialty } = req.params; // Obtém a especialidade a partir dos parâmetros da URL
const snapshot = await db.collection('nutricionista')
.where('especialidade', '==', specialty)
.get();

if (snapshot.empty) {
return res.status(404).json({ message: 'Nenhum nutricionista encontrado com essa especialidade.' });
async getBySpecialty(req, res) {
try {
const { specialty } = req.params; // Obtém a especialidade a partir dos parâmetros da URL
const snapshot = await db.collection('nutricionista')
.where('especialidade', '==', specialty)
.get();

if (snapshot.empty) {
return res.status(404).json({ message: 'Nenhum nutricionista encontrado com essa especialidade.' });
}

const nutricionistas = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
res.status(200).json(nutricionistas);
} catch (error) {
res.status(500).json({ error: error.message });
}
},

const nutricionistas = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
res.status(200).json(nutricionistas);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
// Buscar nutricionistas pelo nome
async getByName(req, res) {
try {
const { nome } = req.params;

const startAt = nome;
const endAt = nome + '\uf8ff';

const snapshot = await db.collection('nutricionistas')
.orderBy('nome')
.startAt(startAt)
.endAt(endAt)
.get();

if (snapshot.empty) {
return res.status(404).json({ message: 'Nenhum nutricionista encontrado com esse nome.' });
}

const nutricionistas = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
res.status(200).json(nutricionistas);
} catch (error) {
res.status(500).json({ error: error.message });
}
},
};


Expand Down
26 changes: 26 additions & 0 deletions backend/controllers/planoAlimentarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ const planoAlimentarController = {
} catch (error) {
res.status(500).json({ error: error.message });
}
},

// Obter planos alimentares de um paciente passando o seu id como parâmetro
async getByPaciente(req, res) {
try {
const { paciente } = req.params;

if (!paciente) {
return res.status(400).json({ error: 'O parâmetro paciente é obrigatório.' });
}

const snapshot = await db.collection('planosAlimentares')
.where('paciente', '==', paciente)
.get();

if (snapshot.empty) {
return res.status(404).json({ message: 'Nenhum plano alimentar encontrado para este paciente.' });
}

const planos = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));

return res.status(200).json(planos);

} catch (error) {
res.status(500).json({ error: error.message });
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion backend/controllers/refeicaoController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const db = require('../firebase-config');
const Refeicao = require('../model/refeicao');
const Refeicao = require('../model/Refeicao');

const refeicaoController = {
//Criar uma nova refeição
Expand Down
15 changes: 14 additions & 1 deletion backend/firebase-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
require("dotenv").config();
const admin = require("firebase-admin");
const serviceAccount = require("./healthway-a0e87.json");

const serviceAccount = {type: process.env.TYPE,
project_id: process.env.PROJECT_ID,
private_key_id: process.env.PRIVATE_KEY_ID,
private_key: process.env.PRIVATE_KEY.replace(/\\n/g, '\n'),
client_email: process.env.CLIENT_EMAIL,
client_id: process.env.CLIENT_ID,
auth_uri: process.env.AUTH_URI,
token_uri: process.env.TOKEN_URI,
auth_provider_x509_cert_url: process.env.AUTH_PROVIDER_X509_CERT_URL,
client_x509_cert_url: process.env.CLIENT_X509_CERT_URL,
universe_domain: process.env.UNIVERSE_DOMAIN,
};

admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
Expand Down
5 changes: 5 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
testEnvironment: 'node',
testMatch: ['**/backend/tests/**/*.test.js'],
verbose: true
};
Loading

0 comments on commit e33d3cc

Please sign in to comment.