diff --git a/client/src/app/app.component.html b/client/src/app/app.component.html index 6165640..2182d2b 100644 --- a/client/src/app/app.component.html +++ b/client/src/app/app.component.html @@ -1,9 +1,5 @@

Welcome to {{title}}

- -
\ No newline at end of file + + diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 1fef4b2..5558935 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -1,7 +1,4 @@ -import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; -import { IPagination } from './models/pagination'; -import { IProduct } from './models/product'; @Component({ selector: 'app-root', @@ -10,17 +7,8 @@ import { IProduct } from './models/product'; }) export class AppComponent implements OnInit { title = 'E-Commerce'; - products: IProduct[]; - constructor(private http: HttpClient) {} + constructor() {} - ngOnInit(): void { - this.http.get('https://localhost:5001/api/products?pageSize=50').subscribe( - { - next: (response: IPagination) => { this.products = response.data; }, - error: (e: any) => { console.log(e); }, - complete: () => { console.log('complete'); } - } - ); - } -} \ No newline at end of file + ngOnInit(): void {} +} diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 11749b0..3bd3175 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -5,18 +5,20 @@ import { HttpClientModule } from '@angular/common/http'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { NavBarComponent } from './nav-bar/nav-bar.component'; +import { CoreModule } from './core/core.module'; +import { ShopModule } from './shop/shop.module'; @NgModule({ declarations: [ - AppComponent, - NavBarComponent + AppComponent ], imports: [ BrowserModule, AppRoutingModule, BrowserAnimationsModule, - HttpClientModule + HttpClientModule, + CoreModule, + ShopModule ], providers: [], bootstrap: [AppComponent] diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts new file mode 100644 index 0000000..64a61b4 --- /dev/null +++ b/client/src/app/core/core.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { NavBarComponent } from './nav-bar/nav-bar.component'; + + + +@NgModule({ + declarations: [NavBarComponent], + imports: [ + CommonModule + ], + exports: [NavBarComponent] +}) +export class CoreModule { } diff --git a/client/src/app/nav-bar/nav-bar.component.html b/client/src/app/core/nav-bar/nav-bar.component.html similarity index 100% rename from client/src/app/nav-bar/nav-bar.component.html rename to client/src/app/core/nav-bar/nav-bar.component.html diff --git a/client/src/app/nav-bar/nav-bar.component.scss b/client/src/app/core/nav-bar/nav-bar.component.scss similarity index 100% rename from client/src/app/nav-bar/nav-bar.component.scss rename to client/src/app/core/nav-bar/nav-bar.component.scss diff --git a/client/src/app/nav-bar/nav-bar.component.ts b/client/src/app/core/nav-bar/nav-bar.component.ts similarity index 100% rename from client/src/app/nav-bar/nav-bar.component.ts rename to client/src/app/core/nav-bar/nav-bar.component.ts diff --git a/client/src/app/models/pagination.ts b/client/src/app/shared/models/pagination.ts similarity index 100% rename from client/src/app/models/pagination.ts rename to client/src/app/shared/models/pagination.ts diff --git a/client/src/app/models/product.ts b/client/src/app/shared/models/product.ts similarity index 100% rename from client/src/app/models/product.ts rename to client/src/app/shared/models/product.ts diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts new file mode 100644 index 0000000..76cf203 --- /dev/null +++ b/client/src/app/shared/shared.module.ts @@ -0,0 +1,12 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + + + +@NgModule({ + declarations: [], + imports: [ + CommonModule + ] +}) +export class SharedModule { } diff --git a/client/src/app/shop/shop-routing.module.ts b/client/src/app/shop/shop-routing.module.ts new file mode 100644 index 0000000..570746c --- /dev/null +++ b/client/src/app/shop/shop-routing.module.ts @@ -0,0 +1,12 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + + + +@NgModule({ + declarations: [], + imports: [ + CommonModule + ] +}) +export class ShopRoutingModule { } diff --git a/client/src/app/shop/shop.component.html b/client/src/app/shop/shop.component.html new file mode 100644 index 0000000..b85f8db --- /dev/null +++ b/client/src/app/shop/shop.component.html @@ -0,0 +1,5 @@ + diff --git a/client/src/app/shop/shop.component.scss b/client/src/app/shop/shop.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/client/src/app/shop/shop.component.ts b/client/src/app/shop/shop.component.ts new file mode 100644 index 0000000..3a76bdc --- /dev/null +++ b/client/src/app/shop/shop.component.ts @@ -0,0 +1,26 @@ +import { Component, OnInit } from '@angular/core'; +import { IProduct } from '../shared/models/product'; +import { ShopService } from './shop.service'; + +@Component({ + selector: 'app-shop', + templateUrl: './shop.component.html', + styleUrls: ['./shop.component.scss'] +}) +export class ShopComponent implements OnInit { + + products: IProduct[]; + + constructor(private shopService: ShopService) { } + + ngOnInit(): void { + this.shopService.getProducts().subscribe( + { + next: (response) => { this.products = response.data; }, + error: (e: any) => { console.log(e); }, + complete: () => { console.log('complete'); } + } + ); + } + +} diff --git a/client/src/app/shop/shop.module.ts b/client/src/app/shop/shop.module.ts new file mode 100644 index 0000000..80eef53 --- /dev/null +++ b/client/src/app/shop/shop.module.ts @@ -0,0 +1,16 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { ShopComponent } from './shop.component'; + + + +@NgModule({ + declarations: [ + ShopComponent + ], + imports: [ + CommonModule + ], + exports: [ShopComponent] +}) +export class ShopModule { } diff --git a/client/src/app/shop/shop.service.ts b/client/src/app/shop/shop.service.ts new file mode 100644 index 0000000..38dd86d --- /dev/null +++ b/client/src/app/shop/shop.service.ts @@ -0,0 +1,16 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IPagination } from '../shared/models/pagination'; + +@Injectable({ + providedIn: 'root' +}) +export class ShopService { + baseURL = 'https://localhost:5001/api/' + + constructor(private http: HttpClient) { } + + getProducts(){ + return this.http.get(this.baseURL + 'products'); + } +}