BETTERZON-42: Refactoring components and creating product detail component

This commit is contained in:
Patrick Müller 2020-12-07 21:37:12 +01:00
parent 4f3a755f78
commit ad1e758325
25 changed files with 72 additions and 11 deletions

View File

@ -4,10 +4,11 @@ import {NgModule} from '@angular/core';
import {AppComponent} from './app.component'; import {AppComponent} from './app.component';
import {AppRouting} from './app.routing'; import {AppRouting} from './app.routing';
import {ProductListComponent} from './product-list/product-list.component'; import {ProductListComponent} from './components/product-list/product-list.component';
import { LandingpageComponent } from './landingpage/landingpage.component'; import { LandingpageComponent } from './components/landingpage/landingpage.component';
import { ProductDetailPageComponent } from './product-detail-page/product-detail-page.component'; import { ProductDetailPageComponent } from './components/product-detail-page/product-detail-page.component';
import { FooterComponent } from './footer/footer.component'; import { FooterComponent } from './components/footer/footer.component';
import { ProductDetailsComponent } from './components/product-details/product-details.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -15,7 +16,8 @@ import { FooterComponent } from './footer/footer.component';
ProductListComponent, ProductListComponent,
LandingpageComponent, LandingpageComponent,
ProductDetailPageComponent, ProductDetailPageComponent,
FooterComponent FooterComponent,
ProductDetailsComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -2,9 +2,9 @@ import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common'; import {CommonModule} from '@angular/common';
import {RouterModule, Routes} from '@angular/router'; import {RouterModule, Routes} from '@angular/router';
import {AppComponent} from './app.component'; import {AppComponent} from './app.component';
import {ProductListComponent} from './product-list/product-list.component'; import {ProductListComponent} from './components/product-list/product-list.component';
import {LandingpageComponent} from './landingpage/landingpage.component'; import {LandingpageComponent} from './components/landingpage/landingpage.component';
import {ProductDetailPageComponent} from './product-detail-page/product-detail-page.component'; import {ProductDetailPageComponent} from './components/product-detail-page/product-detail-page.component';
const routes: Routes = [ const routes: Routes = [
{path: '', component: LandingpageComponent}, {path: '', component: LandingpageComponent},

View File

@ -0,0 +1 @@
<p>product-details works!</p>

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProductDetailsComponent } from './product-details.component';
describe('ProductDetailsComponent', () => {
let component: ProductDetailsComponent;
let fixture: ComponentFixture<ProductDetailsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProductDetailsComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ProductDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-product-details',
templateUrl: './product-details.component.html',
styleUrls: ['./product-details.component.css']
})
export class ProductDetailsComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

View File

@ -1,6 +1,6 @@
import {Component, Input, OnInit} from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import {ApiService} from '../api.service'; import {ApiService} from '../../services/api.service';
import {Product} from '../models/product'; import {Product} from '../../models/product';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
@Component({ @Component({

View File

@ -0,0 +1,7 @@
export interface Price {
price_id: number;
product_id: number;
vendor_id: number;
price_in_cents: number;
timestamp: Date;
}

View File

@ -1,7 +1,8 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http'; import {HttpClient, HttpHeaders} from '@angular/common/http';
import process from 'process'; import process from 'process';
import {Product} from './models/product'; import {Product} from '../models/product';
import {Price} from '../models/price';
import {Observable, of} from 'rxjs'; import {Observable, of} from 'rxjs';
@Injectable({ @Injectable({
@ -24,4 +25,14 @@ export class ApiService {
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); 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`);
}
}
} }