Skip to content
Snippets Groups Projects
Commit 6baf22b2 authored by Nico's avatar Nico
Browse files

Merge branch 'main' of gitlab.c3sl.ufpr.br:mgy20/Design-biblioteca

parents e315406f 0f74b43b
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ bool ControladorUsuarios::adicionarUsuario(string nome, string CPF, string ender
});
if (it != this->usuarios.end()){
cout << "> Erro: Usuario com esse CPF já existe, ignorando inserção" << endl;
cerr << "> Erro: Usuario com esse CPF já existe, ignorando inserção" << endl;
return false;
}
......@@ -46,12 +46,12 @@ int ControladorUsuarios::registrarEmprestimo(string CPF, DescricaoObra descricao
});
if (it == usuarios.end()) {
cout << "> Erro: Usuario não encontrado" << endl;
cerr << "> Erro: Usuario não encontrado" << endl;
return -1;
}
if (!it->emprestar(descricao)){
cout << "> Erro: Falha ao realizar um emprestimo" << endl;
cerr << "> Erro: Falha ao realizar um emprestimo" << endl;
return -1;
}
......@@ -68,12 +68,12 @@ int ControladorUsuarios::retornarEmprestimo(string CPF, DescricaoObra descricao)
});
if (it == usuarios.end()) {
cout << "> Erro: Usuario não encontrado" << endl;
cerr << "> Erro: Usuario não encontrado" << endl;
return -1;
}
if (!it->devolver(descricao)){
cout << "> Erro: Falha ao realizar a devolução" << endl;
cerr << "> Erro: Falha ao realizar a devolução" << endl;
return -1;
}
......@@ -89,7 +89,7 @@ int ControladorUsuarios::recuperarMultas(string CPF){
});
if (it == usuarios.end()) {
cout << "> Erro: Usuario não encontrado" << endl;
cerr << "> Erro: Usuario não encontrado" << endl;
return -1;
}
......@@ -105,7 +105,7 @@ bool ControladorUsuarios::registrarMultaPaga(string CPF, int valor){
});
if (it == usuarios.end()) {
cout << "> Erro: Usuario não encontrado" << endl;
cerr << "> Erro: Usuario não encontrado" << endl;
return false;
}
......
......@@ -14,3 +14,12 @@ void Emprestimo::mostraDetalhes() const {
descricao.mostrarDetalhes();
}
// Methods
void Emprestimo::removeEmprestimo(){
}
string Emprestimo::getDescricaoTitulo(){
return this->descricao.getTitulo();
}
......@@ -16,6 +16,7 @@ class Emprestimo {
// Methods
void removeEmprestimo();
string getDescricaoTitulo();
};
......
#include <exception>
#include <iostream>
#include <algorithm>
#include "Emprestimo.hpp"
#include "Usuario.hpp"
using namespace std;
......@@ -24,12 +27,41 @@ void Usuario::mostrarDetalhes() const {
// Methods
bool Usuario::emprestar(DescricaoObra descricao){
return 0;
// Check number of Borrowed works
if (this->emprestimos->size() >= 3) {
cerr << "Erro: Usuario já possui três empresimos! Ignorando operação";
return false;
}
// Create Emprestimo
try {
Emprestimo emp(0, descricao);
} catch (const exception&) {
cerr << "Erro: Falha ao criar um emprestimo!" << endl;
return false;
}
return true;
}
bool Usuario::devolver(DescricaoObra descricao){
return 0;
// Search for Borrowed work
auto emp_it = find_if(this->emprestimos->begin(), this->emprestimos->end(), [&descricao](Emprestimo& emp){
return emp.getDescricaoTitulo() == descricao.getTitulo();
});
if (emp_it == this->emprestimos->end()){
cerr << "Erro: Obra não encontrada nos emprestimos do Usuário!";
return false;
}
emp_it->removeEmprestimo();
// Remove work
this->emprestimos->erase(emp_it);
return true;
}
// Increase fees
......@@ -47,6 +79,7 @@ int Usuario::getMulta(){
}
bool Usuario::pagarMulta(int valor){
// Check if the user has fees
if (this->multas <= 0) {
cout << "> Aviso: Usuario não possui multas! Ignorando operação" << endl;
......@@ -55,7 +88,7 @@ bool Usuario::pagarMulta(int valor){
// Check if the value is suficient
if (this->multas > valor) {
cout << "> Erro: Valor insuficiente para pagar as multas!" << endl;
cerr << "> Erro: Valor insuficiente para pagar as multas!" << endl;
return false;
}
......
......@@ -2,8 +2,10 @@
#define __USUARIO__
#include <string>
#include <vector>
#include "DescricaoObra.hpp"
#include "./DescricaoObra.hpp"
#include "./Emprestimo.hpp"
using namespace std;
......@@ -15,7 +17,7 @@ class Usuario {
string telefone;
string email;
int multas;
//Emprestimos emp;
vector<Emprestimo> emprestimos[3];
public:
// Constructor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment