Skip to content

Commit

Permalink
Subindo o Projeto
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo committed Dec 22, 2024
1 parent ea6989b commit 5d0d4e4
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 488 deletions.
9 changes: 9 additions & 0 deletions alunos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"alunos": [
{
"id": "1",
"nome": "Rodolfo",
"idade": 30
}
]
}
3 changes: 3 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,8 @@
}
}
}
},
"cli": {
"analytics": "061cf1f4-62ee-4b87-9563-6f86351bd246"
}
}
26 changes: 26 additions & 0 deletions src/app/alunos/alunos.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h1>Cadastro de Alunos</h1>
<hr>
<form>
<p>Nome: <input type="text" name="name" [(ngModel)]="aluno.nome"></p>
<p>Idade: <input type="text" name="idade" [(ngModel)]="aluno.idade"></p>
<button type="button" (click)="cadastrar()">Cadastrar</button>
</form>

<hr>
<h1>Alunos Cadastrados</h1>
<table>
<tr>
<th>Nome</th>
<th>Idade</th>
<th>Ações</th>
</tr>

<tr *ngFor="let aluno of alunos">
<td>{{aluno.nome }}</td>
<td>{{aluno.idade}}</td>
<td><button (click)="atualizar(aluno.id)">Atulizar</button></td>
<td><button (click)="remover(aluno.id)">Remover</button></td>

</tr>
</table>

Empty file.
23 changes: 23 additions & 0 deletions src/app/alunos/alunos.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { AlunosComponent } from './alunos.component';

describe('AlunosComponent', () => {
let component: AlunosComponent;
let fixture: ComponentFixture<AlunosComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ AlunosComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(AlunosComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
52 changes: 52 additions & 0 deletions src/app/alunos/alunos.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Observable } from 'rxjs';
import { AlunoModel } from '../model/aluno.model';
import { AlunosService } from './../service/alunos.service';
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-alunos',
templateUrl: './alunos.component.html',
styleUrls: ['./alunos.component.scss'],
})
export class AlunosComponent implements OnInit {
aluno: AlunoModel = new AlunoModel();

alunos: Array<any> = new Array();

constructor(private alunosService: AlunosService) {}

ngOnInit(): void {
this.listaAlunos();
}

cadastrar() {
this.alunosService.cadastroAluno(this.aluno).subscribe((aluno) => {
this.aluno = new AlunoModel();
this.listaAlunos();
});
}

atualizar(id: string) {
this.alunosService.atualizar(id, this.aluno).subscribe((aluno) => {
this.aluno = new AlunoModel();
this.listaAlunos();
});
}

remover(id: string) {
this.alunosService.remover(id).subscribe((aluno) => {
this.listaAlunos()
})
}

listaAlunos() {
this.alunosService.listaAlunos().subscribe(
(alunos) => {
this.alunos = alunos;
},
(err) => {
console.log('Erro ao chamar o endpoint', err);
}
);
}
}
4 changes: 2 additions & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const routes: Routes = [];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
exports: [RouterModule],
})
export class AppRoutingModule { }
export class AppRoutingModule {}
Loading

0 comments on commit 5d0d4e4

Please sign in to comment.