Skip to content

Commit

Permalink
Merge branch 'dev' into kaua
Browse files Browse the repository at this point in the history
  • Loading branch information
iuryFilho authored Jan 21, 2025
2 parents bace728 + 332f4f6 commit 65a0c71
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 285 deletions.
74 changes: 19 additions & 55 deletions backend/controllers/alimentoController.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,68 @@
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 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 });
}
},

async getByCategory(req, res) {
try {
const { nome } = req.params;

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

const snapshot = await db.collection('alimentos')
.orderBy('Categoria')
.startAt(startAt)
.endAt(endAt)
.get();

if (snapshot.empty) {
return res.status(404).json({ message: 'Nenhum alimento encontrado nessa categoria.' });
}

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 });
}
},
};

module.exports = alimentoController;
2 changes: 1 addition & 1 deletion backend/controllers/nutricionistaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,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
38 changes: 38 additions & 0 deletions backend/services/alimentoService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const db = require('../firebase-config');
const Alimento = require('../model/Alimento');

const AlimentoService = {
async create(data) {
const alimento = new Alimento(data);
return await db.collection('alimentos').add(alimento.toFirestore());
},

async getAll() {
const snapshot = await db.collection('alimentos').get();
return snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
},

async getByCategory(categoria) {
const snapshot = await db.collection('alimentos').where('Categoria', '==', categoria).get();
return snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
},

async getById(id) {
const doc = await db.collection('alimentos').doc(id).get();
if (!doc.exists) {
throw new Error('Alimento não encontrado.');
}
return { id: doc.id, ...doc.data() };
},

async update(id, data) {
const alimento = new Alimento(data);
await db.collection('alimentos').doc(id).update(alimento.toFirestore());
},

async delete(id) {
await db.collection('alimentos').doc(id).delete();
},
};

module.exports = AlimentoService;
118 changes: 67 additions & 51 deletions healthway_app/lib/geral_screens/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,76 @@ class ChatScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
foregroundColor: Colors.white,
title: Row(
children: [
CircleAvatar(
backgroundColor: kPrimaryColor,
radius: 20,
child: Icon(Icons.person, color: Colors.white),
),
SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Nutricionista',
style: TextStyle(fontSize: 16, color: Colors.white)),
Text('Online',
style: TextStyle(fontSize: 12, color: Colors.white70)),
],
),
],
),
backgroundColor: kPrimaryColor,
actions: [
IconButton(icon: Icon(Icons.video_call), onPressed: () {}),
IconButton(icon: Icon(Icons.call), onPressed: () {}),
IconButton(icon: Icon(Icons.more_vert), onPressed: () {}),
appBar: _buildAppBar(),
body: _buildBody(),
);
}

AppBar _buildAppBar() {
return AppBar(
foregroundColor: Colors.white,
title: Row(
children: [
CircleAvatar(
backgroundColor: kPrimaryColor,
radius: 20,
child: Icon(Icons.person, color: Colors.white),
),
SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Nutricionista',
style: TextStyle(fontSize: 16, color: Colors.white)),
Text('Online',
style: TextStyle(fontSize: 12, color: Colors.white70)),
],
),
],
),
body: Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
children: [
Expanded(
child: Obx(() {
return ListView.builder(
reverse: true,
itemCount: chatController.messages.length,
itemBuilder: (context, index) {
final message = chatController.messages[index];
return ChatMessageBubble(message: message);
},
);
}),
),
ChatInputField(
onSendMessage: (String text) {
chatController.sendMessage(text);
},
),
],
),
backgroundColor: kPrimaryColor,
actions: _buildAppBarActions(),
);
}

List<Widget> _buildAppBarActions() {
return [
IconButton(icon: Icon(Icons.video_call), onPressed: () {}),
IconButton(icon: Icon(Icons.call), onPressed: () {}),
IconButton(icon: Icon(Icons.more_vert), onPressed: () {}),
];
}

Widget _buildBody() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
children: [
_buildMessagesList(),
ChatInputField(
onSendMessage: (String text) {
chatController.sendMessage(text);
},
),
],
),
);
}

Widget _buildMessagesList() {
return Expanded(
child: Obx(() {
return ListView.builder(
reverse: true,
itemCount: chatController.messages.length,
itemBuilder: (context, index) {
final message = chatController.messages[index];
return ChatMessageBubble(message: message);
},
);
}),
);
}
}
78 changes: 49 additions & 29 deletions healthway_app/lib/geral_screens/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,35 +226,55 @@ class _LoginScreenState extends State<LoginScreen> {
String userType = _userType;

// Call the login service
_servicesFacade
.login(email: email, senha: senha, userType: userType)
.then((userData) {
if (userData != null) {
if (_userType == 'Paciente') {
Navigator.pushReplacementNamed(context, '/home_patient',
arguments: userData);
} else if (_userType == 'Nutricionista') {
Navigator.pushReplacementNamed(context, '/home_nutritionist',
arguments: userData);
}
} else {
setState(() {
_isLoading = false;
});
// Show error message
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Falha no login. Verifique suas credenciais.')),
);
}
}).catchError((error) {
setState(() {
_isLoading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Erro ao fazer login: ${error.toString()}')),
);
});
// _servicesFacade
// .login(email: email, senha: senha, userType: userType)
// .then((userData) {
// if (userData != null) {
// if (_userType == 'Paciente') {
// Navigator.pushReplacementNamed(context, '/home_patient',
// arguments: userData);
// } else if (_userType == 'Nutricionista') {
// Navigator.pushReplacementNamed(context, '/home_nutritionist',
// arguments: userData);
// }
// } else {
// setState(() {
// _isLoading = false;
// });
// // Show error message
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(
// content: Text('Falha no login. Verifique suas credenciais.')),
// );
// }
// }).catchError((error) {
// setState(() {
// _isLoading = false;
// });
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(content: Text('Erro ao fazer login: ${error.toString()}')),
// );
// });

var mockData = {
'nome': 'John Doe',
'email': 'exemplo@email.com',
'dt_nascimento': '01/01/2000',
'altura': 180,
'peso': 75,
'circunferencia_abdominal': 88,
'massa_muscular': 6.5,
'gordura_corporal': 15.5,
'alergias': ['Amendoim', 'Leite'],
'preferencias': ['Vegano'],
};
if (_userType == 'Paciente') {
Navigator.pushReplacementNamed(context, '/home_patient',
arguments: mockData);
} else if (_userType == 'Nutricionista') {
Navigator.pushReplacementNamed(context, '/home_nutritionist',
arguments: mockData);
}
}
}

Expand Down
Loading

0 comments on commit 65a0c71

Please sign in to comment.