Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.

Commit 619a7b3

Browse files
committed
feat: component the handle DELETE method
1 parent 4f8de2a commit 619a7b3

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

web/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { MatSortModule } from '@angular/material/sort';
3030
import localePt from '@angular/common/locales/pt';
3131
import { registerLocaleData } from '@angular/common';
3232
import { ProductUpdateComponent } from './components/product/product-update/product-update.component';
33+
import { ProductRemoveComponent } from './components/product/product-remove/product-remove.component';
3334

3435
registerLocaleData(localePt);
3536

@@ -45,7 +46,8 @@ registerLocaleData(localePt);
4546
ProductCreateComponent,
4647
ProductReadComponent,
4748
MatTemplateTableComponent,
48-
ProductUpdateComponent
49+
ProductUpdateComponent,
50+
ProductRemoveComponent
4951
],
5052
imports: [
5153
BrowserModule,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "../product-create/product-create.component.css";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<mat-card>
2+
<mat-card-title>Remove '{{ product.nome }}'?</mat-card-title>
3+
<form>
4+
<mat-form-field>
5+
<input matInput placeholder="Name" name="name" [(ngModel)]="product.nome">
6+
</mat-form-field>
7+
<mat-form-field>
8+
<input matInput placeholder="Description" name="description" [(ngModel)]="product.descricao">
9+
</mat-form-field>
10+
<mat-form-field>
11+
<input matInput placeholder="Price (R$)" name="price" [(ngModel)]="product.precoUnitario">
12+
</mat-form-field>
13+
</form>
14+
15+
<button (click)="delete()" mat-raised-button color="warn">
16+
Remove
17+
</button>
18+
<button (click)="navigateToProducts()" mat-raised-button>
19+
Cancel
20+
</button>
21+
</mat-card>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { ActivatedRoute, Router } from '@angular/router';
3+
import { Product } from '../product.model';
4+
import { ProductService } from '../product.service';
5+
6+
@Component({
7+
selector: "app-product-remove",
8+
templateUrl: "./product-remove.component.html",
9+
styleUrls: ["./product-remove.component.css"],
10+
})
11+
export class ProductRemoveComponent implements OnInit {
12+
product: Product;
13+
14+
constructor(
15+
private service: ProductService,
16+
private router: Router,
17+
private route: ActivatedRoute
18+
) {}
19+
20+
ngOnInit(): void {
21+
const id = this.route.snapshot.paramMap.get("id");
22+
this.service.getById(id).subscribe((found) => {
23+
this.product = found;
24+
})
25+
}
26+
27+
delete(): void {
28+
const idToDelete = this.product.id.toString();
29+
this.service.delete(idToDelete).subscribe(() => {
30+
this.service.showMessage(
31+
`The item id. ${idToDelete} was removed from database.`
32+
);
33+
});
34+
this.navigateToProducts();
35+
}
36+
37+
navigateToProducts(): void {
38+
this.router.navigate(["/products"]);
39+
}
40+
}

0 commit comments

Comments
 (0)