2022-05-13 13:26:38 -07:00
|
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
2022-05-12 16:52:52 -07:00
|
|
|
import { Injectable } from '@angular/core';
|
2022-05-13 13:26:38 -07:00
|
|
|
import { IBrand } from '../shared/models/brand';
|
2022-05-12 16:52:52 -07:00
|
|
|
import { IPagination } from '../shared/models/pagination';
|
2022-05-13 13:26:38 -07:00
|
|
|
import { IType } from '../shared/models/producttype';
|
|
|
|
import { map } from 'rxjs/operators'
|
|
|
|
import { ShopParams } from '../shared/models/shopparams';
|
2022-05-12 16:52:52 -07:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class ShopService {
|
|
|
|
baseURL = 'https://localhost:5001/api/'
|
|
|
|
|
|
|
|
constructor(private http: HttpClient) { }
|
|
|
|
|
2022-05-13 13:26:38 -07:00
|
|
|
getProducts(shopParams: ShopParams){
|
|
|
|
let params = new HttpParams();
|
|
|
|
|
|
|
|
if (shopParams.brandId !== 0){
|
|
|
|
params = params.append('brandId', shopParams.brandId.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(shopParams.typeId !== 0){
|
|
|
|
params = params.append('typeId', shopParams.typeId.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shopParams.search){
|
|
|
|
params = params.append('search', shopParams.search);
|
|
|
|
}
|
|
|
|
|
|
|
|
params = params.append('sort', shopParams.sort);
|
|
|
|
params = params.append('pageIndex', shopParams.pageNumber.toString());
|
|
|
|
params = params.append('pageIndex', shopParams.pageSize.toString());
|
|
|
|
|
|
|
|
return this.http.get<IPagination>(this.baseURL + 'products', {observe: 'response', params})
|
|
|
|
.pipe(
|
|
|
|
map(response => {
|
|
|
|
return response.body;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getBrands(){
|
|
|
|
return this.http.get<IBrand[]>(this.baseURL + 'products/brands');
|
|
|
|
}
|
|
|
|
|
|
|
|
getTypes(){
|
|
|
|
return this.http.get<IType[]>(this.baseURL + 'products/types');
|
2022-05-12 16:52:52 -07:00
|
|
|
}
|
|
|
|
}
|