-
diff --git a/client/src/app/components/products-list/products-list.component.ts b/client/src/app/components/products-list/products-list.component.ts
index 48a03e9..95499ac 100644
--- a/client/src/app/components/products-list/products-list.component.ts
+++ b/client/src/app/components/products-list/products-list.component.ts
@@ -20,9 +20,8 @@ import {MatSort} from '@angular/material/sort';
import {Product} from '../../interfaces/product';
import {ProductService} from '../../services/app/product.service';
import {MatDialog} from '@angular/material/dialog';
-import {ProductDialogComponent} from '../product-dialog/product-dialog.component';
import {MatButton, MatIconButton} from '@angular/material/button';
-import {MatFormField} from '@angular/material/form-field';
+import {MatFormField, MatLabel} from '@angular/material/form-field';
import {MatIcon} from '@angular/material/icon';
import {MatInput} from '@angular/material/input';
import {CurrencyPipe} from '@angular/common';
@@ -49,7 +48,8 @@ import {CurrencyPipe} from '@angular/common';
MatSort,
MatTable,
MatHeaderCellDef,
- CurrencyPipe
+ CurrencyPipe,
+ MatLabel
],
styleUrls: ['./products-list.component.css']
})
@@ -100,31 +100,11 @@ export class ProductsListComponent implements OnInit, AfterViewInit, OnChanges {
}
onAdd(): void {
- const ref = this.dialog.open(ProductDialogComponent, {
- data: {product: {id: '', name: '', brand: undefined}},
- width: '420px'
- });
- ref.afterClosed().subscribe((result?: Product) => {
- if (result) {
- this.add.emit(result);
- this.productService.addProduct(result).subscribe(() => this.loadProducts());
- }
- });
}
onEdit(product: Product): void {
- const ref = this.dialog.open(ProductDialogComponent, {
- data: {product: {...product}},
- width: '420px'
- });
- ref.afterClosed().subscribe((result?: Product) => {
- if (result) {
- this.edit.emit(result);
- this.productService.updateProduct((product as any).id, result).subscribe(() => this.loadProducts());
- }
- });
}
onDelete(product: Product): void {
diff --git a/client/src/app/pages/add-product/add-product.component.ts b/client/src/app/pages/add-product/add-product.component.ts
index ac6f109..694fa28 100644
--- a/client/src/app/pages/add-product/add-product.component.ts
+++ b/client/src/app/pages/add-product/add-product.component.ts
@@ -178,12 +178,12 @@ export class AddProductComponent implements OnInit, OnDestroy {
ngOnInit(): void {
- this.brandSubscription = this.brandService.getBrands().subscribe({
+ this.brandSubscription = this.brandService.getAll().subscribe({
next: (brands: Brand[]) => {
this.brands = this.normalizeIds(brands, 'id');
this.filteredBrands = [...this.brands];
},
- error: (error) => {
+ error: (error: any) => {
console.error('Error fetching brands:', error);
},
complete: () => {
@@ -191,12 +191,12 @@ export class AddProductComponent implements OnInit, OnDestroy {
}
});
- this.platformSubscription = this.platformService.getPlatforms().subscribe({
+ this.platformSubscription = this.platformService.getAll().subscribe({
next: (platforms: Platform[]) => {
this.platforms = this.normalizeIds(platforms, 'id');
this.filteredPlatforms = [...this.platforms];
},
- error: (error) => {
+ error: (error: any) => {
console.error('Error fetching platforms:', error);
},
complete: () => {
@@ -204,11 +204,11 @@ export class AddProductComponent implements OnInit, OnDestroy {
}
});
- this.categorySubscription = this.categoryService.getCategories().subscribe({
+ this.categorySubscription = this.categoryService.getAll().subscribe({
next: (categories: Category[]) => {
this.categories = this.normalizeIds(categories, 'id');
},
- error: (error) => {
+ error: (error: any) => {
console.error('Error fetching categories:', error);
},
complete: () => {
diff --git a/client/src/app/services/app/brand.service.ts b/client/src/app/services/app/brand.service.ts
index e7801aa..44426c5 100644
--- a/client/src/app/services/app/brand.service.ts
+++ b/client/src/app/services/app/brand.service.ts
@@ -1,31 +1,32 @@
import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
+import {Observable} from 'rxjs';
import {Brand} from '../../interfaces/brand';
+import {CrudService} from '../crud.service';
@Injectable({
providedIn: 'root'
})
-export class BrandService {
-
+export class BrandService implements CrudService
{
private readonly http = inject(HttpClient);
private readonly BASE_URL = 'http://localhost:3000/api/app/brands';
- getBrands() {
+ getAll(): Observable {
return this.http.get(this.BASE_URL, {withCredentials: true});
}
- addBrand(brand: Brand) {
- console.log("Adding brand:", brand);
- return this.http.post(this.BASE_URL, brand, {withCredentials: true});
+ add(item: Brand): Observable {
+ console.log('Adding brand:', item);
+ return this.http.post(this.BASE_URL, item, {withCredentials: true});
}
- updateBrand(id: string, brand: Brand) {
- console.log("Updating brand:", id, brand);
- return this.http.put(`${this.BASE_URL}/${id}`, brand, {withCredentials: true});
+ update(id: string | number, item: Brand): Observable {
+ console.log('Updating brand:', id, item);
+ return this.http.put(`${this.BASE_URL}/${id}`, item, {withCredentials: true});
}
- deleteBrand(id: string) {
- console.log("Deleting brand:", id);
- return this.http.delete(`${this.BASE_URL}/${id}`, {withCredentials: true});
+ delete(id: string | number): Observable {
+ console.log('Deleting brand:', id);
+ return this.http.delete(`${this.BASE_URL}/${id}`, {withCredentials: true});
}
}
diff --git a/client/src/app/services/app/category.service.ts b/client/src/app/services/app/category.service.ts
index 0c47cb3..2f3147c 100644
--- a/client/src/app/services/app/category.service.ts
+++ b/client/src/app/services/app/category.service.ts
@@ -1,31 +1,32 @@
import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
+import {Observable} from 'rxjs';
import {Category} from '../../interfaces/category';
+import {CrudService} from '../crud.service';
@Injectable({
providedIn: 'root'
})
-export class CategoryService {
-
+export class CategoryService implements CrudService {
private readonly http = inject(HttpClient);
private readonly BASE_URL = 'http://localhost:3000/api/app/categories';
- getCategories() {
+ getAll(): Observable {
return this.http.get(this.BASE_URL, {withCredentials: true});
}
- addCategory(category: Category) {
- console.log("Adding category:", category);
- return this.http.post(this.BASE_URL, category, {withCredentials: true});
+ add(item: Category): Observable {
+ console.log('Adding category:', item);
+ return this.http.post(this.BASE_URL, item, {withCredentials: true});
}
- updateCategory(id: string, category: Category) {
- console.log("Updating category:", id, category);
- return this.http.put(`${this.BASE_URL}/${id}`, category, {withCredentials: true});
+ update(id: string | number, item: Category): Observable {
+ console.log('Updating category:', id, item);
+ return this.http.put(`${this.BASE_URL}/${id}`, item, {withCredentials: true});
}
- deleteCategory(id: string) {
- console.log("Deleting category:", id);
- return this.http.delete(`${this.BASE_URL}/${id}`, {withCredentials: true});
+ delete(id: string | number): Observable {
+ console.log('Deleting category:', id);
+ return this.http.delete(`${this.BASE_URL}/${id}`, {withCredentials: true});
}
}
diff --git a/client/src/app/services/app/platform.service.ts b/client/src/app/services/app/platform.service.ts
index 8147153..3bfa156 100644
--- a/client/src/app/services/app/platform.service.ts
+++ b/client/src/app/services/app/platform.service.ts
@@ -1,31 +1,32 @@
import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
+import {Observable} from 'rxjs';
import {Platform} from '../../interfaces/platform';
+import {CrudService} from '../crud.service';
@Injectable({
providedIn: 'root'
})
-export class PlatformService {
-
+export class PlatformService implements CrudService {
private readonly http = inject(HttpClient);
private readonly BASE_URL = 'http://localhost:3000/api/app/platforms';
- getPlatforms() {
+ getAll(): Observable {
return this.http.get(this.BASE_URL, {withCredentials: true});
}
- addPlatform(platform: Platform) {
- console.log("Adding platform:", platform);
- return this.http.post(this.BASE_URL, platform, {withCredentials: true});
+ add(item: Platform): Observable {
+ console.log('Adding platform:', item);
+ return this.http.post(this.BASE_URL, item, {withCredentials: true});
}
- updatePlatform(id: string, platform: Platform) {
- console.log("Updating platform:", id, platform);
- return this.http.put(`${this.BASE_URL}/${id}`, platform, {withCredentials: true});
+ update(id: string | number, item: Platform): Observable {
+ console.log('Updating platform:', id, item);
+ return this.http.put(`${this.BASE_URL}/${id}`, item, {withCredentials: true});
}
- deletePlatform(id: string) {
- console.log("Deleting platform:", id);
- return this.http.delete(`${this.BASE_URL}/${id}`, {withCredentials: true});
+ delete(id: string | number): Observable {
+ console.log('Deleting platform:', id);
+ return this.http.delete(`${this.BASE_URL}/${id}`, {withCredentials: true});
}
}
diff --git a/client/src/app/services/crud.service.ts b/client/src/app/services/crud.service.ts
new file mode 100644
index 0000000..8f3e81d
--- /dev/null
+++ b/client/src/app/services/crud.service.ts
@@ -0,0 +1,8 @@
+import { Observable } from 'rxjs';
+
+export interface CrudService {
+ getAll(): Observable;
+ add(item: T): Observable;
+ update(id: string | number, item: T): Observable;
+ delete(id: string | number): Observable;
+}