This repository was archived by the owner on Jul 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct.service.ts
More file actions
94 lines (74 loc) · 4.53 KB
/
Copy pathproduct.service.ts
File metadata and controls
94 lines (74 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { AccountService } from './account.service';
@Injectable({
providedIn: 'root'
})
export class ProductService {
private apiUrl = '/api/v1';
constructor(private http: HttpClient, private accountService: AccountService) {}
private get authHeaders(): HttpHeaders {
return new HttpHeaders({
'Authorization': `Bearer ${this.accountService.token}`
});
}
// Products
getProducts(): Observable<{ success: boolean; message: string; data: any[] }> {
return this.http.get<{ success: boolean; message: string; data: any[] }>(`${this.apiUrl}/products`);
}
getAllProducts(): Observable<{ success: boolean; message: string; data: any[] }> {
return this.http.get<{ success: boolean; message: string; data: any[] }>(`${this.apiUrl}/products?showHidden=true`);
}
getProductDetail(id: number): Observable<{ success: boolean; message: string; data: any }> {
return this.http.get<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/products/${id}/detail`);
}
createProduct(data: any): Observable<{ success: boolean; message: string; data: any }> {
return this.http.post<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/products`, data, { headers: this.authHeaders });
}
updateProduct(id: number, data: any): Observable<{ success: boolean; message: string; data: any }> {
return this.http.put<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/products/${id}`, data, { headers: this.authHeaders });
}
deleteProduct(id: number): Observable<{ success: boolean; message: string }> {
return this.http.delete<{ success: boolean; message: string }>(`${this.apiUrl}/products/${id}`, { headers: this.authHeaders });
}
// Categories
getCategories(): Observable<{ success: boolean; message: string; data: any[] }> {
return this.http.get<{ success: boolean; message: string; data: any[] }>(`${this.apiUrl}/categories`);
}
createCategory(data: any): Observable<{ success: boolean; message: string; data: any }> {
return this.http.post<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/categories`, data, { headers: this.authHeaders });
}
updateCategory(id: number, data: any): Observable<{ success: boolean; message: string; data: any }> {
return this.http.put<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/categories/${id}`, data, { headers: this.authHeaders });
}
deleteCategory(id: number): Observable<{ success: boolean; message: string }> {
return this.http.delete<{ success: boolean; message: string }>(`${this.apiUrl}/categories/${id}`, { headers: this.authHeaders });
}
// Customization Slots
getSlotsByProductId(productId: number): Observable<{ success: boolean; message: string; data: any[] }> {
return this.http.get<{ success: boolean; message: string; data: any[] }>(`${this.apiUrl}/slots/product/${productId}/detail`);
}
createSlot(data: any): Observable<{ success: boolean; message: string; data: any }> {
return this.http.post<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/slots`, data, { headers: this.authHeaders });
}
updateSlot(id: number, data: any): Observable<{ success: boolean; message: string; data: any }> {
return this.http.put<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/slots/${id}`, data, { headers: this.authHeaders });
}
deleteSlot(id: number): Observable<{ success: boolean; message: string }> {
return this.http.delete<{ success: boolean; message: string }>(`${this.apiUrl}/slots/${id}`, { headers: this.authHeaders });
}
// Customization Options
addOptionToSlot(slotId: number, data: any): Observable<{ success: boolean; message: string; data: any }> {
return this.http.post<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/slots/${slotId}/options`, { ...data, slotId }, { headers: this.authHeaders });
}
updateOptionInSlot(slotId: number, data: any): Observable<{ success: boolean; message: string; data: any }> {
return this.http.put<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/slots/${slotId}/options`, data, { headers: this.authHeaders });
}
removeOptionFromSlot(slotId: number, productId: number): Observable<{ success: boolean; message: string }> {
return this.http.delete<{ success: boolean; message: string }>(`${this.apiUrl}/slots/${slotId}/options`, {
headers: this.authHeaders,
body: { productId }
});
}
}