Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/aluno.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
73 changes: 70 additions & 3 deletions src/biblioteca.ts
Original file line number Diff line number Diff line change
@@ -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 = "";
Expand Down Expand Up @@ -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;
}
}



6 changes: 6 additions & 0 deletions src/emprestimo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface Emprestimo{
livro: Livro;
aluno: Aluno;
dataEmprestimo: Date;
dataDevolucao: Date;
}
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ document.addEventListener("DOMContentLoaded", () => {
biblioteca.adicionarLivro(livro8);
biblioteca.adicionarLivro(livro9);

const aluno1 = new Aluno("Lisandra", "[email protected]", "A28", "123");
const aluno2 = new Aluno("Maria", "[email protected]", "A29", "123");
const aluno1 = new Aluno("Lisandra", "[email protected]", "123","A28");
const aluno2 = new Aluno("Maria", "[email protected]", "123", "A29" );

biblioteca.adicionarAluno(aluno1);
biblioteca.adicionarAluno(aluno2);
Expand All @@ -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
Expand All @@ -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);
});
});
//});
38 changes: 28 additions & 10 deletions src/livro.ts
Original file line number Diff line number Diff line change
@@ -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 = `<span>${this.titulo}</span> (Autor: ${this.autor})`;
li.classList.add("livro-item");
if (!this.disponivel) {
li.classList.add("emprestado");
const li = document.createElement("li");
li.innerHTML = `<span>${this.titulo}</span> (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.`);
}
}
}


11 changes: 11 additions & 0 deletions src/usuario.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"compilerOptions": {
{"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Projects */
Expand Down