BETTERZON-42: Refactoring components and creating product detail component

This commit is contained in:
2020-12-07 21:37:12 +01:00
parent 4f3a755f78
commit ad1e758325
25 changed files with 72 additions and 11 deletions
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ApiService } from './api.service';
describe('ApiService', () => {
let service: ApiService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ApiService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+38
View File
@@ -0,0 +1,38 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import process from 'process';
import {Product} from '../models/product';
import {Price} from '../models/price';
import {Observable, of} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ApiService {
apiUrl = 'https://backend.betterzon.xyz';
constructor(
private http: HttpClient
) {
}
getProducts(): Observable<Product[]> {
try {
const prods = this.http.get<Product[]>((this.apiUrl + '/products'));
console.log(prods);
return prods;
} catch (exception) {
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
}
}
getPrices(): Observable<Price[]> {
try {
const prices = this.http.get<Price[]>((this.apiUrl + '/prices'));
console.log(prices);
return prices;
} catch (exception) {
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
}
}
}