From 2b2adec77fe7296d3e76a79f6710bc52ed153d69 Mon Sep 17 00:00:00 2001 From: Mateus Felipe Date: Sat, 8 Oct 2022 10:41:49 -0300 Subject: [PATCH] Delete User --- .../TMSProject/controllers/PessoaController.java | 6 ++++++ frontend/main/src/app/users/users.component.html | 2 +- frontend/main/src/app/users/users.component.ts | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java index 814b6c5..6ffcfc6 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java @@ -11,6 +11,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -101,6 +102,11 @@ public boolean disBounce(@PathVariable("id") int id) { public Pessoa register(@RequestBody Pessoa dados) { return pessoaRepository.save(dados); } + + @DeleteMapping("/{id}") + public void deletePessoa(@PathVariable("id") int id){ + pessoaRepository.deleteById(id); + } private List obterListaCompleta() { diff --git a/frontend/main/src/app/users/users.component.html b/frontend/main/src/app/users/users.component.html index 4e89484..531d363 100644 --- a/frontend/main/src/app/users/users.component.html +++ b/frontend/main/src/app/users/users.component.html @@ -107,7 +107,7 @@

New User

{{user.document}} {{user.birth}} - + diff --git a/frontend/main/src/app/users/users.component.ts b/frontend/main/src/app/users/users.component.ts index 5da8a72..c1bd87c 100644 --- a/frontend/main/src/app/users/users.component.ts +++ b/frontend/main/src/app/users/users.component.ts @@ -14,6 +14,7 @@ name!:string email!:string document!:string birth!:string +id!: number constructor(public usersService: UsersService, private router: Router, private http: HttpClient) { } @@ -27,13 +28,14 @@ birth!:string for (let i = 0; i < count; i++) { + this.id = response[i].id; this.name = response[i].nome; this.email = response[i].email; this.document = response[i].document; this.birth = response[i].birth; - this.users.push({name:this.name, email:this.email, document:this.document, birth:this.birth}); + this.users.push({id: this.id, name:this.name, email:this.email, document:this.document, birth:this.birth}); } @@ -62,8 +64,11 @@ birth!:string this.users.push({name:this.name, email:this.email, document:this.document, birth:this.birth}); } - deletar(){ + deletar(id:number){ + + console.log(id); + this.http.delete('http://localhost:8080/user/'+id); } alterar(){