Skip to content

Commit

Permalink
Merge pull request #104 from ES2-UFPI/iury
Browse files Browse the repository at this point in the history
Terceira Release
  • Loading branch information
iuryFilho authored Jan 21, 2025
2 parents e33d3cc + bc56892 commit 2e6093d
Show file tree
Hide file tree
Showing 93 changed files with 19,093 additions and 1,583 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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)
name: Start & Test (API)

on:
push:
Expand All @@ -24,17 +24,17 @@ jobs:
- name: Create .env file
working-directory: backend
run: |
echo "TYPE=${{ secrets.TYPE }}" > .env
echo "TYPE=${{ vars.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 "AUTH_URI=${{ vars.AUTH_URI }}" >> .env
echo "TOKEN_URI=${{ vars.TOKEN_URI }}" >> .env
echo "AUTH_PROVIDER_X509_CERT_URL=${{ vars.AUTH_PROVIDER_X509_CERT_URL }}" >> .env
echo "CLIENT_X509_CERT_URL=${{ secrets.CLIENT_X509_CERT_URL }}" >> .env
echo "UNIVERSE_DOMAIN=${{ secrets.UNIVERSE_DOMAIN }}" >> .env
echo "UNIVERSE_DOMAIN=${{ vars.UNIVERSE_DOMAIN }}" >> .env
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Healthway
## Tutorial Instalação para Android

```bash
flutter build apk --split-per-abi
flutter install --use-application-binary=build\app\outputs\flutter-apk\app-arm64-v8a-release.apk
```
63 changes: 30 additions & 33 deletions backend/controllers/alimentoController.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,77 @@
const db = require('../firebase-config');
const Alimento = require('../model/Alimento');
const AlimentoService = require('../services/alimentoService');


const alimentoController = {
//Criar um novo alimento
async create(req, res){
async create(req, res) {
try {
const alimento = new Alimento(req.body);
await db.collection('alimentos').add(alimento.toFirestore());
await AlimentoService.create(req.body);
res.status(201).json({ message: 'Alimento criado com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
}
},

//Obter todos os alimentos
async getAll(req, res){
async createMany(req, res) {
try {
await AlimentoService.createMany(req.body);
res.status(201).json({ message: 'Alimentos criados com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
}
},

async getAll(req, res) {
try {
const snapshot = await db.collection('alimentos').get();
const alimentos = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
const alimentos = await AlimentoService.getAll();
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() }));
const alimentos = await AlimentoService.getByCategory(categoria);
res.status(200).json(alimentos);
} catch (error) {
res.status(500).json({ error: error.message });
}
},

//Obter um alimento pelo ID
async getById(req, res){

async getById(req, res) {
try {
const { id } = req.params;
const doc = await db.collection('alimentos').doc(id).get();

if (!doc.exists) {
return res.status(404).json({ error: 'Alimento não encontrado.' });
}

res.status(200).json({ id: doc.id, ...doc.data() });
const alimento = await AlimentoService.getById(id);
res.status(200).json(alimento);
} catch (error) {
res.status(500).json({ error: error.message });
if (error.message === 'Alimento não encontrado.') {
res.status(404).json({ error: error.message });
} else {
res.status(500).json({ error: error.message });
}
}
},

//Atualizar um alimento
async update(req, res){
async update(req, res) {
try {
const { id } = req.params;
const alimento = new Alimento(req.body);

await db.collection('alimentos').doc(id).update(alimento.toFirestore());
await AlimentoService.update(id, req.body);
res.status(200).json({ message: 'Alimento atualizado com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
}
},

//Excluir um alimento
async delete(req, res){
async delete(req, res) {
try {
const { id } = req.params;
await db.collection('alimentos').doc(id).delete();
await AlimentoService.delete(id);
res.status(200).json({ message: 'Alimento excluído com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
}
}
},
};

module.exports = alimentoController;
18 changes: 17 additions & 1 deletion backend/controllers/nutricionistaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ const nutricionistaController = {
}
},

async getByEmailAndPassword(req, res) {
try {
const { email, senha } = req.body;
const snapshot = await db.collection('nutricionista').where('email', '==', email).where('senha', '==', senha).get();
const paciente = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));

if (paciente.length === 0) {
return res.status(404).json({ error: 'Nutricionista não encontrado.' });
}

res.status(200).json(paciente[0]);
} catch (error) {
res.status(500).json({ error: error.message });
}
},

// Atualizar um nutricionista
async update(req, res) {
try {
Expand Down Expand Up @@ -88,7 +104,7 @@ const nutricionistaController = {
const { nome } = req.params;

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

const snapshot = await db.collection('nutricionistas')
.orderBy('nome')
Expand Down
44 changes: 39 additions & 5 deletions backend/controllers/pacienteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const pacienteController = {
// Criar um paciente
async create(req, res) {
try {
const paciente = new Paciente(req.body);
await db.collection('paciente').add(paciente.toFirestore());
res.status(201).json({ message: 'Paciente criado com sucesso!' });
const paciente = new Paciente();
paciente.fromJson(req.body);
await db.collection('paciente').add(paciente.toFirestore());
res.status(201).json({ message: 'Paciente criado com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
res.status(500).json({ error: error.message });
}
},

Expand Down Expand Up @@ -40,11 +41,44 @@ const pacienteController = {
}
},

async getByListOfIds(req, res) {
try {
const { ids } = req.body;
const pacientes = [];
for (const id of ids) {
const doc = await db.collection('paciente').doc(id).get();
if (doc.exists) {
pacientes.push({ id: doc.id, ...doc.data() });
}
}
res.status(200).json(pacientes);
} catch (error) {
res.status(500).json({ error: error.message });
}
},

async getByEmailAndPassword(req, res) {
try {
const { email, senha } = req.body;
const snapshot = await db.collection('paciente').where('email', '==', email).where('senha', '==', senha).get();
const paciente = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));

if (paciente.length === 0) {
return res.status(404).json({ error: 'Paciente não encontrado.' });
}

res.status(200).json(paciente[0]);
} catch (error) {
res.status(500).json({ error: error.message });
}
},

// Atualizar um paciente
async update(req, res) {
try {
const { id } = req.params;
const paciente = new Paciente(req.body);
const paciente = new Paciente();
paciente.fromJson(req.body);

await db.collection('paciente').doc(id).update(paciente.toFirestore());
res.status(200).json({ message: 'Paciente atualizado com sucesso!' });
Expand Down
33 changes: 29 additions & 4 deletions backend/controllers/planoAlimentarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,48 @@ const planoAlimentarController = {
}
},

// Obter planos alimentares de um paciente passando o seu id como parâmetro
async getByPaciente(req, res) {
// Obter um plano alimentar 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)
const snapshot = await db.collection('plano_alimentar')
.where('id_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() }));

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

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

async getByNutricionista (req, res) {
try {
const { nutricionista } = req.params;

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

const snapshot = await db.collection('plano_alimentar')
.where('id_nutricionista', '==', nutricionista)
.get();

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

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

return res.status(200).json(planos);
Expand Down
69 changes: 45 additions & 24 deletions backend/model/Alimento.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class Alimento {
constructor(
categoria,
descricao,
{descricao,
umidade,
energiaKcal,
energiaKJ,
Expand All @@ -19,9 +18,8 @@ class Alimento {
sodio,
potassio,
cobre,
zinco
zinco}
) {
this.categoria = categoria; // Categoria do Alimento
this.descricao = descricao; // Descrição dos alimentos
this.umidade = umidade; // Umidade (%)
this.energiaKcal = energiaKcal; // Energia (Kcal)
Expand All @@ -45,28 +43,51 @@ class Alimento {

toFirestore() {
return {
categoria: this.categoria,
descricao: this.descricao,
umidade: this.umidade,
energiaKcal: this.energiaKcal,
energiaKJ: this.energiaKJ,
proteina: this.proteina,
lipideos: this.lipideos,
colesterol: this.colesterol,
carboidrato: this.carboidrato,
fibraAlimentar: this.fibraAlimentar,
cinzas: this.cinzas,
calcio: this.calcio,
magnesio: this.magnesio,
manganes: this.manganes,
fosforo: this.fosforo,
ferro: this.ferro,
sodio: this.sodio,
potassio: this.potassio,
cobre: this.cobre,
zinco: this.zinco
"Descrição dos alimentos": this.descricao,
"Umidade (%)": this.umidade,
"Energia (Kcal)": this.energiaKcal,
"Energia (KJ)": this.energiaKJ,
"Proteína (g)": this.proteina,
"Lipídeos (g)": this.lipideos,
"Colesterol (mg)": this.colesterol,
"Carboidrato (g)": this.carboidrato,
"Fibra Alimentar (g)": this.fibraAlimentar,
"Cinzas (g)": this.cinzas,
"Cálcio (mg)": this.calcio,
"Magnésio (mg)": this.magnesio,
"Manganês (mg)": this.manganes,
"Fósforo (mg)": this.fosforo,
"Ferro (mg)": this.ferro,
"Sódio (mg)": this.sodio,
"Potássio (mg)": this.potassio,
"Cobre (mg)": this.cobre,
"Zinco (mg)": this.zinco
};
}

static fromJson(json) {
return new Alimento({
descricao: json["Descrição dos alimentos"],
umidade: json["Umidade (%)"],
energiaKcal: json["Energia (Kcal)"],
energiaKJ: json["Energia (KJ)"],
proteina: json["Proteína (g)"],
lipideos: json["Lipídeos (g)"],
colesterol: json["Colesterol (mg)"],
carboidrato: json["Carboidrato (g)"],
fibraAlimentar: json["Fibra Alimentar (g)"],
cinzas: json["Cinzas (g)"],
calcio: json["Cálcio (mg)"],
magnesio: json["Magnésio (mg)"],
manganes: json["Manganês (mg)"],
fosforo: json["Fósforo (mg)"],
ferro: json["Ferro (mg)"],
sodio: json["Sódio (mg)"],
potassio: json["Potássio (mg)"],
cobre: json["Cobre (mg)"],
zinco: json["Zinco (mg)"]
});
}
}

module.exports = Alimento;
Loading

0 comments on commit 2e6093d

Please sign in to comment.