Skip to content

Commit 002f74a

Browse files
committed
End of section 10
1 parent 604aaab commit 002f74a

18 files changed

+207
-71
lines changed

client/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<app-header></app-header>
22

33
<div class="container mt-6">
4-
<app-shop></app-shop>
4+
<router-outlet></router-outlet>
55
</div>

client/src/app/app.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Component } from '@angular/core';
22
import { RouterOutlet } from '@angular/router';
33
import { HeaderComponent } from "./layout/header/header.component";
4-
import { ShopComponent } from "./features/shop/shop.component";
54

65
@Component({
76
selector: 'app-root',
8-
imports: [RouterOutlet, HeaderComponent, ShopComponent],
7+
imports: [RouterOutlet, HeaderComponent],
98
templateUrl: './app.component.html',
109
styleUrl: './app.component.scss'
1110
})

client/src/app/app.routes.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import { Routes } from '@angular/router';
2+
import { HomeComponent } from './features/home/home.component';
3+
import { ShopComponent } from './features/shop/shop.component';
4+
import { ProductDetailsComponent } from './features/shop/product-details/product-details.component';
25

3-
export const routes: Routes = [];
6+
export const routes: Routes = [
7+
{ path: '', component: HomeComponent },
8+
{ path: 'shop', component: ShopComponent },
9+
{ path: 'shop/:id', component: ProductDetailsComponent },
10+
{ path: '**', redirectTo: '', pathMatch: 'full' }
11+
];

client/src/app/core/services/shop.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export class ShopService {
3838
return this.http.get<Pagination<Product>>(this.baseUrl + 'products', { params })
3939
}
4040

41+
getProduct(id: number) {
42+
return this.http.get<Product>(this.baseUrl + 'products/' + id);
43+
}
44+
4145
getBrands() {
4246
if (this.brands.length > 0) return;
4347

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>home works!</p>

client/src/app/features/home/home.component.scss

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-home',
5+
imports: [],
6+
templateUrl: './home.component.html',
7+
styleUrl: './home.component.scss'
8+
})
9+
export class HomeComponent {
10+
11+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@if (product) {
2+
<section class="py-8">
3+
<div class="max-w-7xl px-4 mx-auto">
4+
<div class="grid grid-cols-2 gap-8">
5+
<div class="max-w-7xl mx-auto">
6+
<img class="w-full" src="{{product.pictureUrl}}" alt="product image">
7+
</div>
8+
9+
<div>
10+
<h1 class="text-2xl font-semibold text-gray-900">{{product.name}}</h1>
11+
<div class="mt-4 items-center gap-4 flex">
12+
<p class="text-3xl font-extrabold text-gray-900">
13+
{{product.price | currency}}
14+
</p>
15+
</div>
16+
17+
<div class="flex gap-4 mt-6">
18+
<button mat-flat-button class="match-input-height">
19+
<mat-icon>shopping_cart</mat-icon>
20+
Add to cart
21+
</button>
22+
23+
<mat-form-field appearance="outline" class="flex">
24+
<mat-label>Quantity</mat-label>
25+
<input matInput type="number">
26+
</mat-form-field>
27+
</div>
28+
29+
<mat-divider></mat-divider>
30+
31+
<p class="mt-6 text-gray-500">
32+
{{product.description}}
33+
</p>
34+
</div>
35+
</div>
36+
</div>
37+
</section>
38+
}

client/src/app/features/shop/product-details/product-details.component.scss

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Component, inject, OnInit } from '@angular/core';
2+
import { ShopService } from '../../../core/services/shop.service';
3+
import { ActivatedRoute } from '@angular/router';
4+
import { Product } from '../../../shared/models/product';
5+
import { CurrencyPipe } from '@angular/common';
6+
import { MatButton } from '@angular/material/button';
7+
import { MatIcon } from '@angular/material/icon';
8+
import { MatFormField, MatLabel } from '@angular/material/form-field';
9+
import { MatInput } from '@angular/material/input';
10+
import { MatDivider } from '@angular/material/divider';
11+
12+
@Component({
13+
selector: 'app-product-details',
14+
imports: [
15+
CurrencyPipe,
16+
MatButton,
17+
MatIcon,
18+
MatFormField,
19+
MatInput,
20+
MatLabel,
21+
MatDivider
22+
],
23+
templateUrl: './product-details.component.html',
24+
styleUrl: './product-details.component.scss'
25+
})
26+
export class ProductDetailsComponent implements OnInit {
27+
private shopService = inject(ShopService);
28+
private activatedRoute = inject(ActivatedRoute);
29+
product?: Product;
30+
31+
ngOnInit(): void {
32+
this.loadProduct();
33+
}
34+
35+
loadProduct() {
36+
const id = this.activatedRoute.snapshot.paramMap.get('id');
37+
if (!id) return;
38+
39+
this.shopService.getProduct(+id).subscribe({
40+
next: product => this.product = product,
41+
error: error => console.log(error)
42+
})
43+
}
44+
}

0 commit comments

Comments
 (0)