diff --git a/src/aluno.ts b/src/aluno.ts
new file mode 100644
index 0000000..667602c
--- /dev/null
+++ b/src/aluno.ts
@@ -0,0 +1,8 @@
+class Aluno extends Usuario {
+ matricula : string;
+
+ constructor(nome: string, email : string, senha : string, matricula: string) {
+ super(nome, email, senha);
+ this.matricula = matricula;
+ }
+}
\ No newline at end of file
diff --git a/src/biblioteca.ts b/src/biblioteca.ts
index 0002f28..01fdf4b 100644
--- a/src/biblioteca.ts
+++ b/src/biblioteca.ts
@@ -1,9 +1,19 @@
-/*
+class Biblioteca {
+ livros: Livro [] = [];
+ alunos: Aluno [] = [];
+ emprestimos: Emprestimo[] = [];
+
+ constructor(
+ public livrosDisponiveisElement: HTMLUListElement,
+ public emprestimosAtivosElement: HTMLUListElement
+ ) {}
+
+
// --------- [Não mexer] Responsaveis por renderizar no html
private renderizarLivrosDisponiveis(): void {
this.livrosDisponiveisElement.innerHTML = "";
- const disponiveis = this.livros.filter((livro) => livro.disponivel);
+ const disponiveis = this.livros.filter((livro) => livro.estaDisponivel);
const selectLivro = document.getElementById("livro") as HTMLSelectElement;
selectLivro.innerHTML = "";
@@ -35,4 +45,61 @@
// --------- [Não mexer] Responsaveis por renderizar no html
- */
+ adicionarLivro(livro: Livro): void {
+ this.livros.push(livro);
+ this.renderizarLivrosDisponiveis();
+ }
+ encontrarLivro(id: number): Livro {
+ const livroEncontrado =
+ this.livros.find((livro) => livro.id === id) || ({} as Livro);
+ return livroEncontrado;
+
+ }
+ adicionarAluno(aluno: Aluno) {
+ this.alunos.push(aluno);
+ }
+
+ encontrarAluno(matricula: string): Aluno{
+ return this.alunos.find((aluno) => aluno.matricula === matricula) as Aluno;
+
+ }
+
+ realizarEmprestimo(livro: Livro, aluno: Aluno, senha: string){
+ if (!aluno.matricula){
+ alert("matricula inexistente");
+ return false;
+ }
+
+ if(!senha || senha !== aluno.senha){
+ alert("senha incorreta ou inexistente!")
+ return false;
+ }
+
+ if(!livro.estaDisponivel) {
+ alert(`o livro ${livro.titulo} nao esta disponivel para emprestimo.`);
+ return false;
+ }
+
+ livro.emprestarLivro();
+
+ const dataEmprestimo = new Date();
+ const dataDevolucao = new Date();
+ dataDevolucao.setDate(dataDevolucao.getDate() + 15);
+
+ const emprestimo: Emprestimo = {
+ livro,
+ aluno,
+ dataEmprestimo,
+ dataDevolucao,
+ };
+
+ this.emprestimos.push(emprestimo);
+ this.renderizarEmprestimosAtivos();
+ this.renderizarLivrosDisponiveis();
+
+ return true;
+ }
+}
+
+
+
diff --git a/src/emprestimo.ts b/src/emprestimo.ts
new file mode 100644
index 0000000..0af0210
--- /dev/null
+++ b/src/emprestimo.ts
@@ -0,0 +1,6 @@
+interface Emprestimo{
+ livro: Livro;
+ aluno: Aluno;
+ dataEmprestimo: Date;
+ dataDevolucao: Date;
+}
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index 2ad4ced..4dfcb9a 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -31,8 +31,8 @@ document.addEventListener("DOMContentLoaded", () => {
biblioteca.adicionarLivro(livro8);
biblioteca.adicionarLivro(livro9);
- const aluno1 = new Aluno("Lisandra", "lisandra@example.com", "A28", "123");
- const aluno2 = new Aluno("Maria", "maria@example.com", "A29", "123");
+ const aluno1 = new Aluno("Lisandra", "lisandra@example.com", "123","A28");
+ const aluno2 = new Aluno("Maria", "maria@example.com", "123", "A29" );
biblioteca.adicionarAluno(aluno1);
biblioteca.adicionarAluno(aluno2);
@@ -42,7 +42,7 @@ document.addEventListener("DOMContentLoaded", () => {
) as HTMLFormElement;
alugarLivroForm.addEventListener("submit", (event) => {
- event.preventDefault();
+ event.preventDefault();})
const idLivroSelecionado = parseInt(
(document.getElementById("livro") as HTMLSelectElement).value
@@ -51,10 +51,12 @@ document.addEventListener("DOMContentLoaded", () => {
.value;
const senha = (document.getElementById("senha") as HTMLInputElement).value;
+
+
const livro = (biblioteca.encontrarLivro(idLivroSelecionado) ||
{}) as Livro;
const aluno = (biblioteca.encontrarAluno(matricula) || {}) as Aluno;
- biblioteca.realizarEmprestimo(livro, aluno, senha);
+ //biblioteca.realizarEmprestimo(livro, aluno, senha);
});
-});
+//});
\ No newline at end of file
diff --git a/src/livro.ts b/src/livro.ts
index 14d1172..5d28089 100644
--- a/src/livro.ts
+++ b/src/livro.ts
@@ -1,13 +1,31 @@
-/*
+class Livro {
+ constructor(
+ public id: number,
+ public titulo: string,
+ public autor: string,
+ public estaDisponivel: boolean = true
+ ) {}
+
// --------- [Não mexer] Responsaveis por renderizar no html
criarElementoHTML(): HTMLLIElement {
- const li = document.createElement("li");
- li.innerHTML = `${this.titulo} (Autor: ${this.autor})`;
- li.classList.add("livro-item");
- if (!this.disponivel) {
- li.classList.add("emprestado");
+ const li = document.createElement("li");
+ li.innerHTML = `${this.titulo} (Autor: ${this.autor})`;
+ li.classList.add("livro-item");
+ if (!this.estaDisponivel) {
+ li.classList.add("emprestado");
+ }
+ return li;
}
- return li;
-}
-// --------- [Não mexer] Responsaveis por renderizar no html
-*/
+ // --------- [Não mexer] Responsaveis por renderizar no html
+
+ emprestarLivro() {
+ //if(this.estaDisponivel === true){
+ if (this.estaDisponivel){
+ this.estaDisponivel = false;
+ }else {
+ alert(`o livro "${this.titulo}" não esta disponviel para emprestimo.`);
+ }
+ }
+ }
+
+
\ No newline at end of file
diff --git a/src/usuario.ts b/src/usuario.ts
new file mode 100644
index 0000000..e81f0a2
--- /dev/null
+++ b/src/usuario.ts
@@ -0,0 +1,11 @@
+class Usuario {
+ nome: string;
+ email : string;
+ senha : string;
+
+ constructor(nome: string, email : string, senha : string) {
+ this.nome = nome;
+ this.email = email;
+ this.senha = senha;
+ }
+}
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
index 587be64..7bbb883 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,5 +1,4 @@
-{
- "compilerOptions": {
+{"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */