diff --git a/sources/ControladorObras.o b/sources/ControladorObras.o deleted file mode 100644 index 908ec4754d9bc2991fa28aca9bb1c84aded298be..0000000000000000000000000000000000000000 Binary files a/sources/ControladorObras.o and /dev/null differ diff --git a/sources/ControladorUsuarios.cpp b/sources/ControladorUsuarios.cpp index 82da897d96aab7dcf2bea856ce63047c0e27c5a7..e13249350e1668e9dfa6dc078463b2cfddda357c 100644 --- a/sources/ControladorUsuarios.cpp +++ b/sources/ControladorUsuarios.cpp @@ -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; } diff --git a/sources/DescricaoObra.o b/sources/DescricaoObra.o deleted file mode 100644 index 8a180334ad540b9d1c4abe036f150cdf7b5ce5f2..0000000000000000000000000000000000000000 Binary files a/sources/DescricaoObra.o and /dev/null differ diff --git a/sources/Emprestimo.cpp b/sources/Emprestimo.cpp index e27b253eee5ac13b23d9a7a0cb4bdbc566bda2af..b638d2c29a36ef370bcccbdce0cacabc6217f58b 100644 --- a/sources/Emprestimo.cpp +++ b/sources/Emprestimo.cpp @@ -14,3 +14,12 @@ void Emprestimo::mostraDetalhes() const { descricao.mostrarDetalhes(); } + +// Methods +void Emprestimo::removeEmprestimo(){ + +} + +string Emprestimo::getDescricaoTitulo(){ + return this->descricao.getTitulo(); +} diff --git a/sources/Emprestimo.hpp b/sources/Emprestimo.hpp index f963da0d4abd0c18f7439cdeb087b0a4fb7e0fcd..b8ce99c4b4fc4af41f66b00fc6fcf3b981f36204 100644 --- a/sources/Emprestimo.hpp +++ b/sources/Emprestimo.hpp @@ -16,6 +16,7 @@ class Emprestimo { // Methods void removeEmprestimo(); + string getDescricaoTitulo(); }; diff --git a/sources/Livro.o b/sources/Livro.o deleted file mode 100644 index e2a8e858996ace76a6dbe9851711ee800ca7d531..0000000000000000000000000000000000000000 Binary files a/sources/Livro.o and /dev/null differ diff --git a/sources/Obra.o b/sources/Obra.o deleted file mode 100644 index 98833e4698d1967dcbd20e21b94a2e47ce8bb644..0000000000000000000000000000000000000000 Binary files a/sources/Obra.o and /dev/null differ diff --git a/sources/Periodico.o b/sources/Periodico.o deleted file mode 100644 index e8d98d8378267cd2fc90b85ef330841542419b1b..0000000000000000000000000000000000000000 Binary files a/sources/Periodico.o and /dev/null differ diff --git a/sources/Usuario.cpp b/sources/Usuario.cpp index f53612757ceaac79b73c8bf06390a41410659aab..e5cb15b288cd7151a130e407e2e62a57733ee134 100644 --- a/sources/Usuario.cpp +++ b/sources/Usuario.cpp @@ -1,5 +1,8 @@ +#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; } diff --git a/sources/Usuario.hpp b/sources/Usuario.hpp index 99b7c8119037f7d125a57eb0f61899f2d58a4560..f76d9bc67f4f3e70a61a1aa7b749303053f1af64 100644 --- a/sources/Usuario.hpp +++ b/sources/Usuario.hpp @@ -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