-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from ES2-UFPI/iury
Terceira Release
- Loading branch information
Showing
93 changed files
with
19,093 additions
and
1,583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.