Sky.Net/client/src/app/shop/shop.service.ts

57 lines
1.6 KiB
TypeScript
Raw Normal View History

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-13 15:33:15 -07:00
import { IProduct } from '../shared/models/product';
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;
})
);
}
2022-05-13 15:33:15 -07:00
getProduct(id: number){
return this.http.get<IProduct>(this.baseURL + 'products/' + id);
}
2022-05-13 13:26:38 -07:00
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
}
}