Browse Source

Angular Proxy and Spring Boot Apps

master
Sanjith Sivapuram 4 years ago
parent
commit
93b8913156
31 changed files with 449 additions and 123 deletions
  1. 15
      Shopify-Cart/src/main/java/com/shopify/cart/controller/CartController.java
  2. 48
      Shopify-Cart/src/main/java/com/shopify/cart/controller/ProductController.java
  3. 36
      Shopify-Cart/src/main/java/com/shopify/cart/controller/UserController.java
  4. 3
      Shopify-Cart/src/main/java/com/shopify/cart/repository/CartRepository.java
  5. 4
      Shopify-Cart/src/main/resources/application.properties
  6. 12
      ShopifyUI/proxy.conf.json
  7. 6
      ShopifyUI/src/app/app-routing.module.ts
  8. 27
      ShopifyUI/src/app/auth/login/login.component.css
  9. 42
      ShopifyUI/src/app/auth/login/login.component.html
  10. 33
      ShopifyUI/src/app/auth/login/login.component.ts
  11. 33
      ShopifyUI/src/app/auth/sign-up/sign-up.component.css
  12. 42
      ShopifyUI/src/app/auth/sign-up/sign-up.component.html
  13. 34
      ShopifyUI/src/app/auth/sign-up/sign-up.component.ts
  14. 14
      ShopifyUI/src/app/components/cart/cart.component.css
  15. 11
      ShopifyUI/src/app/components/cart/cart.component.html
  16. 27
      ShopifyUI/src/app/components/cart/cart.component.ts
  17. 7
      ShopifyUI/src/app/components/home/home.component.css
  18. 13
      ShopifyUI/src/app/components/home/home.component.html
  19. 17
      ShopifyUI/src/app/components/payments/payments.component.css
  20. 32
      ShopifyUI/src/app/components/payments/payments.component.html
  21. 16
      ShopifyUI/src/app/components/payments/payments.component.ts
  22. 3
      ShopifyUI/src/app/components/product-detail/product-detail.component.css
  23. 29
      ShopifyUI/src/app/components/product-detail/product-detail.component.html
  24. 31
      ShopifyUI/src/app/components/product-detail/product-detail.component.ts
  25. 4
      ShopifyUI/src/app/components/products/products.component.css
  26. 2
      ShopifyUI/src/app/components/products/products.component.html
  27. 6
      ShopifyUI/src/app/model/review.model.ts
  28. 7
      ShopifyUI/src/app/service/cart.service.ts
  29. 2
      ShopifyUI/src/app/service/product.service.ts
  30. 12
      ShopifyUI/src/app/service/review.service.ts
  31. 4
      ShopifyUI/src/styles.css

15
Shopify-Cart/src/main/java/com/shopify/cart/controller/CartController.java

@ -30,9 +30,18 @@ public class CartController {
@PostMapping("/cart/{uid}/{pid}")
public Cart postCart(@PathVariable("uid") Long uid, @PathVariable("pid") Long pid, @RequestBody Cart cart) {
cart.setUser(userRepository.getById(uid));
cart.setProduct(productRepository.getById(pid));
return cartRepository.save(cart);
List<Cart> cartItems = cartRepository.findByUserAndProduct(uid,pid);
if (cartItems.size() > 0) {
Cart cartDB = cartItems.get(0);
cartDB.setQuantity(cartDB.getQuantity()+cart.getQuantity());
cartDB.setPrice(cartDB.getProduct().getDiscountedPrice()*(cartDB.getQuantity()));
return cartRepository.save(cartDB);
}
else {
cart.setUser(userRepository.getById(uid));
cart.setProduct(productRepository.getById(pid));
return cartRepository.save(cart);
}
}
@GetMapping("/cart/{uid}")

48
Shopify-Cart/src/main/java/com/shopify/cart/controller/ProductController.java

@ -1,48 +0,0 @@
package com.shopify.cart.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.shopify.cart.model.Product;
import com.shopify.cart.repository.ProductRepository;
@RestController
public class ProductController {
@Autowired
private ProductRepository productRepository;
@PostMapping("/product")
public Product postProduct(@RequestBody Product product) {
return productRepository.save(product);
}
@GetMapping("/product")
public List<Product> getAllProducts() {
return productRepository.findAll();
}
@GetMapping("/product/trending")
public List<Product> getAllTrendingProducts() {
return productRepository.findAllByTrending();
}
@GetMapping("/product/{pid}")
public Product getProductById(@PathVariable("pid") Long pid) {
return productRepository.getById(pid);
}
@GetMapping("/product/name/{name}")
public List<Product> showProduct(@PathVariable String name)
{
return productRepository.findAllByName(name);
}
}

36
Shopify-Cart/src/main/java/com/shopify/cart/controller/UserController.java

@ -1,36 +0,0 @@
package com.shopify.cart.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.shopify.cart.model.User;
import com.shopify.cart.repository.UserRepository;
@RestController
public class UserController {
@Autowired
private UserRepository userRepository;
@PostMapping("/user")
public User postUser(@RequestBody User user) {
return userRepository.save(user);
}
@GetMapping("/user")
public List<User> getAllUser() {
return userRepository.findAll();
}
@GetMapping("/user/{uid}")
public User getUserById(@PathVariable("uid") Long uid) {
return userRepository.getById(uid);
}
}

3
Shopify-Cart/src/main/java/com/shopify/cart/repository/CartRepository.java

@ -11,4 +11,7 @@ public interface CartRepository extends JpaRepository<Cart,Long> {
@Query("select c from Cart c join c.user u where u.id=?1")
List<Cart> getCartByUserId(Long uid);
@Query("select c from Cart c join c.user u join c.product p where u.id=?1 and p.id=?2")
List<Cart> findByUserAndProduct(Long uid, Long pid);
}

4
Shopify-Cart/src/main/resources/application.properties

@ -1,10 +1,10 @@
server.port=8002
spring.datasource.url=jdbc:mysql://10.3.117.22:3306/Shopify_DB?createDatabaseIfNotExist=true
spring.datasource.url=jdbc:mysql://10.3.117.26:3306/Shopify_DB?createDatabaseIfNotExist=true
spring.datasource.username=testuser
spring.datasource.password=PASSWORD123
server.servlet.context-path=/api
server.servlet.context-path=/api2
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

12
ShopifyUI/proxy.conf.json

@ -1,6 +1,14 @@
{
"/api": {
"target": "http://10.3.117.22:8002",
"/api1": {
"target": "http://10.3.117.26:8001",
"secure": false
},
"/api2": {
"target": "http://10.3.117.26:8002",
"secure": false
},
"/api3": {
"target": "http://10.3.117.26:8003",
"secure": false
}
}

6
ShopifyUI/src/app/app-routing.module.ts

@ -1,7 +1,10 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './auth/login/login.component';
import { SignUpComponent } from './auth/sign-up/sign-up.component';
import { CartComponent } from './components/cart/cart.component';
import { HomeComponent } from './components/home/home.component';
import { PaymentsComponent } from './components/payments/payments.component';
import { ProductDetailComponent } from './components/product-detail/product-detail.component';
import { ProductsComponent } from './components/products/products.component';
@ -11,6 +14,9 @@ const routes: Routes = [
{ path: 'products', component: ProductsComponent},
{ path: 'products/:product_id', component: ProductDetailComponent},
{ path: 'cart/:user_id', component: CartComponent},
{ path: 'payment', component: PaymentsComponent},
{ path: 'login', component: LoginComponent},
{ path: 'signup', component: SignUpComponent}
];
@NgModule({

27
ShopifyUI/src/app/auth/login/login.component.css

@ -0,0 +1,27 @@
.login_form {
margin: 0px auto;
border: none;
padding: 16px;
height: 440px;
box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-webkit-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-moz-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
}
.login_form input {
width: 100%;
height: 45px;
padding: 12px;
}
.login_form button {
border: none;
background-color: #1F618D;
color: white;
padding: 12px 16px;
width: 100%;
}
.login_form p {
color: #E74C3C;
}

42
ShopifyUI/src/app/auth/login/login.component.html

@ -1 +1,41 @@
<p>login works!</p>
<div class="row navbar">
<div class="col-10">
<h2>Shopify</h2>
</div>
<div class="col-1">
<a routerLink="/home">Home</a>
</div>
<div class="col-1">
<a routerLink="/products">Products</a>
</div>
</div>
<BR><BR><BR><BR><BR><BR>
<div class="row">
<div class="col-3 card login_form text-center">
<h1 style="color: #1B4F72;">LOGIN</h1>
<form [formGroup]='loginForm' (submit)='onLoginFormSubmit()'>
<input type="text" placeholder="Enter Username" formControlName="username" />
<div *ngIf="loginForm.controls['username'].invalid && (loginForm.controls['username'].touched || loginForm.controls['username'].dirty)">
<p>Invalid Username</p>
</div>
<BR><BR>
<input type="password" placeholder="Enter Password" formControlName="password" />
<div *ngIf="loginForm.controls['password'].invalid && (loginForm.controls['password'].touched || loginForm.controls['password'].dirty)">
<p>Invalid Password</p>
</div>
<BR><BR>
<button [disabled]='!loginForm.valid'>Login</button>
</form>
</div>
</div>
<div class="row">
<div class="col-12">
{{msg}}
</div>
</div>
<br>
<div class="row">
<div class="col-12 text-center">
<p style="color: #1B4F72;">Don't have an account ? <a routerLink="/signup">Sign Up</a></p>
</div>
</div>

33
ShopifyUI/src/app/auth/login/login.component.ts

@ -1,4 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { User } from 'src/app/model/user.model';
import { UserService } from 'src/app/service/user.service';
@Component({
selector: 'app-login',
@ -7,9 +11,36 @@ import { Component, OnInit } from '@angular/core';
})
export class LoginComponent implements OnInit {
constructor() { }
loginForm: FormGroup;
msg: String;
constructor(private userService: UserService ,private route: Router) {
this.loginForm = new FormGroup({
username: new FormControl(''),
password: new FormControl('')
})
}
ngOnInit(): void {
this.loginForm = new FormGroup({
username: new FormControl('', Validators.required),
password: new FormControl('', Validators.required)
})
}
onLoginFormSubmit() {
let user: User = {
username: this.loginForm.value.username,
password: this.loginForm.value.password
}
// this.userService.loginUser(user).subscribe(data => {
// window.sessionStorage.setItem("username", user.username);
// window.sessionStorage.setItem("authcode", btoa(user.username + ":" + user.password));
// window.sessionStorage.setItem("isLoggedIn", "true");
// this.route.navigateByUrl("/");
// },
// (err: any) => {
// this.msg = "Invalid Credentials"
// })
}
}

33
ShopifyUI/src/app/auth/sign-up/sign-up.component.css

@ -0,0 +1,33 @@
.login_form {
margin: 0px auto;
border: none;
padding: 16px;
height: 570px;
box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-webkit-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-moz-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
}
.login_form input {
width: 100%;
height: 45px;
padding: 12px;
}
.login_form button {
border: none;
background-color: #1F618D;
color: white;
padding: 12px 16px;
width: 100%;
}
.login_form select {
width: 100%;
height: 45px;
}
.login_form p {
color: #E74C3C;
}

42
ShopifyUI/src/app/auth/sign-up/sign-up.component.html

@ -1 +1,41 @@
<p>sign-up works!</p>
<div class="row navbar">
<div class="col-10">
<h2>Shopify</h2>
</div>
<div class="col-1">
<a routerLink="/home">Home</a>
</div>
<div class="col-1">
<a routerLink="/products">Products</a>
</div>
</div>
<BR><BR><BR><BR><BR><BR>
<div class="row">
<div class="col-3 card login_form text-center">
<h1 style="color: #1B4F72;">SIGN UP</h1>
<form [formGroup]='signUpForm' (submit)='onSignUpFormSubmit()'>
<input type="text" placeholder="Enter Name" formControlName="name" />
<div *ngIf="signUpForm.controls['name'].invalid && (signUpForm.controls['name'].touched || signUpForm.controls['name'].dirty)">
<p>Invalid Name</p>
</div>
<BR><BR>
<input type="text" placeholder="Enter Username" formControlName="username" />
<div *ngIf="signUpForm.controls['username'].invalid && (signUpForm.controls['username'].touched || signUpForm.controls['username'].dirty)">
<p>Invalid Username</p>
</div>
<BR><BR>
<input type="password" placeholder="Enter Password" formControlName="password" />
<div *ngIf="signUpForm.controls['password'].invalid && (signUpForm.controls['password'].touched || signUpForm.controls['password'].dirty)">
<p>Invalid Password</p>
</div>
<BR><BR>
<button [disabled]='!signUpForm.valid'>Sign Up</button>
</form>
</div>
</div>
<br>
<div class="row">
<div class="col-12 text-center">
<p style="color: #1B4F72;">Already have an account ? <a routerLink="/login">Login</a></p>
</div>
</div>

34
ShopifyUI/src/app/auth/sign-up/sign-up.component.ts

@ -1,4 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { User } from 'src/app/model/user.model';
import { UserService } from 'src/app/service/user.service';
@Component({
selector: 'app-sign-up',
@ -7,9 +11,37 @@ import { Component, OnInit } from '@angular/core';
})
export class SignUpComponent implements OnInit {
constructor() { }
signUpForm: FormGroup;
msg: String;
constructor(private userService: UserService, private route: Router) {
this.signUpForm = new FormGroup({
name: new FormControl(''),
username: new FormControl(''),
password: new FormControl(''),
})
}
ngOnInit(): void {
this.signUpForm = new FormGroup({
name: new FormControl('', Validators.required),
username: new FormControl('', Validators.required),
password: new FormControl('', Validators.required)
})
}
onSignUpFormSubmit() {
let user: User = {
name: this.signUpForm.value.name,
username: this.signUpForm.value.username,
password: this.signUpForm.value.password,
}
// this.userService.postUser(user).subscribe(data => {
// this.route.navigateByUrl("/login?msg=sign-up%20success");
// },
// (err: any) => {
// this.msg = "Could Not Sign In";
// })
}
}

14
ShopifyUI/src/app/components/cart/cart.component.css

@ -48,4 +48,18 @@
.cart-content h3 {
color: #1B4F72;
padding-left: 50px;
}
.deleteBtn button {
background-color: transparent;
border: 1px solid #E74C3C;
border-radius: 20px;
color: #E74C3C;
padding: 12px 16px;
transition: 0.2s all linear;
}
.deleteBtn button:hover {
background-color: #E74C3C;
color: white;
}

11
ShopifyUI/src/app/components/cart/cart.component.html

@ -53,9 +53,16 @@
<input type="number" value={{c.quantity}}>
</div>
<div class="col-1 QuantityBtn">
<button style="float: left;" (click)="increaseQty(c.cart_id,c.quantity,c.price)"><i class="bi bi-plus"></i></button>
<button style="float: left;" (click)="increaseQty(c.cart_id,c.quantity,c.product.discountedPrice)"><i class="bi bi-plus"></i></button>
</div>
</div>
<br>
<div class="row">
<div class="col-12 deleteBtn">
<button style="float: right;" (click)="deleteCartItems(c.cart_id)"><i class="bi bi-trash"></i></button>
</div>
</div>
<br>
</div>
</div>
</div>
@ -67,6 +74,6 @@
<h3>Total : Rs {{totalPrice}}</h3>
</div>
<div class="col-6 text-center payBtn">
<button routerLink="/products">Proceed To Pay</button>
<button routerLink="/payment">Proceed To Pay</button>
</div>
</div>

27
ShopifyUI/src/app/components/cart/cart.component.ts

@ -26,10 +26,11 @@ export class CartComponent implements OnInit {
})
}
increaseQty(cid:number,quantity:number,price:number) {
increaseQty(cid:number,quantity:number,discountPrice:number) {
this.totalPrice = 0;
console.log("Increase Quantity")
let qty:number = quantity + 1;
let amount:number = price*qty;
let amount:number = discountPrice*qty;
let cart:Cart = {
quantity : qty,
price : amount
@ -49,8 +50,9 @@ export class CartComponent implements OnInit {
}
decreaseQty(cid:number,quantity:number,price:number) {
this.totalPrice = 0;
console.log("Decrease Quantity")
let amount:number = price/quantity;
let amount:number = price-(price/quantity);
let qty:number = quantity - 1;
let cart:Cart = {
quantity : qty,
@ -70,4 +72,23 @@ export class CartComponent implements OnInit {
})
}
deleteCartItems(cid:number) {
this.totalPrice = 0;
this.cartService.deleteCartItem(cid).subscribe(data => {
this.cartItems.forEach((i, index) => {
if (i.cart_id == cid) {
this.cartItems.splice(index, 1);
}
})
this.cartService.getCartByUser(this.uid).subscribe(data1 => {
this.cartNo = data1.length;
this.cartItems=data1;
console.log(this.cartItems)
this.cartItems.forEach((i,index) => {
this.totalPrice = this.totalPrice + i.price;
})
})
})
}
}

7
ShopifyUI/src/app/components/home/home.component.css

@ -8,8 +8,11 @@
}
.home-heading {
font-size: 13em;
font-weight: 500;
font-size: 7em;
font-weight: 700;
/* background-repeat: no-repeat;
background-size: contain;
background-position: center; */
}
.product {

13
ShopifyUI/src/app/components/home/home.component.html

@ -17,17 +17,20 @@
</div>
<br>
<div class="row">
<div class="col-12 searchBar text-center">
<input #box (keyup.enter)="onSearchEnter(box.value)" placeholder="Search for the Product Here">
<div class="col-12 text-center">
<p class="home-heading" style="color: #1B4F72;">Welcome To Shopify</p>
</div>
</div>
<p>{{searchValue}}</p>
<div>
<div class="row">
<div class="col-12 text-center">
<p class="home-heading" style="color: #1B4F72;">Welcome To Shopify</p>
<p style="color: #1B4F72;">Find the products you like.....</p>
</div>
</div>
<div class="row">
<div class="col-12 text-center">
<img src="https://cdn.shopify.com/shopifycloud/brochure/assets/landers/short-lander/free-trial/default@tablet-83f017c08356e1b69d531716b99faa0ff7ff6cee61097d7f5169a55032d79e73.png" alt="">
</div>
</div>
<div class="row p-5">
<div class="col-4 product pDetails" *ngFor='let p of products'>
<div class="row">

17
ShopifyUI/src/app/components/payments/payments.component.css

@ -0,0 +1,17 @@
.paymentLine {
margin: 0px auto;
box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-webkit-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-moz-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
padding: 12px;
color: #1B4F72;
}
.payBtn button {
border: 1px solid transparent;
padding: 12px 14px;
border-radius: 20px;
color: white;
background-color: #2E86C1;
width: 95%;
}

32
ShopifyUI/src/app/components/payments/payments.component.html

@ -1 +1,31 @@
<p>payments works!</p>
<div class="row navbar">
<div class="col-8">
<h2>Shopify</h2>
</div>
<div class="col-1">
<a routerLink="/home">Home</a>
</div>
<div class="col-1">
<a routerLink="/products">Products</a>
</div>
<div class="col-1 active">
<a routerLink="/cart/{{uid}}">{{cartNo}}&nbsp;&nbsp;<i class="bi bi-cart3"></i>Cart</a>
</div>
<div class="col-1 loginbtn">
<a routerLink="/login">Login</a>
</div>
</div>
<br><br>
<div class="row">
<div class="col-10 paymentLine">
<div>
<h3>We only take cash on delivery</h3>
</div>
</div>
</div>
<br><br>
<div class="row">
<div class="col-12 text-center payBtn">
<button routerLink="/order">Proceed To Checkout</button>
</div>
</div>

16
ShopifyUI/src/app/components/payments/payments.component.ts

@ -1,4 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Cart } from 'src/app/model/cart.model';
import { CartService } from 'src/app/service/cart.service';
@Component({
selector: 'app-payments',
@ -7,9 +9,21 @@ import { Component, OnInit } from '@angular/core';
})
export class PaymentsComponent implements OnInit {
constructor() { }
uid:string = "1";
cartNo: number = 0;
cartItems: Cart[] = [];
totalPrice: number = 0;
constructor(private cartService: CartService) { }
ngOnInit(): void {
this.cartService.getCartByUser(this.uid).subscribe(data1 => {
this.cartNo = data1.length;
this.cartItems=data1;
console.log(this.cartItems)
this.cartItems.forEach((i,index) => {
this.totalPrice = this.totalPrice + i.price;
})
})
}
}

3
ShopifyUI/src/app/components/product-detail/product-detail.component.css

@ -15,3 +15,6 @@
width: 95%;
}
.username {
font-weight: 700;
}

29
ShopifyUI/src/app/components/product-detail/product-detail.component.html

@ -39,13 +39,38 @@
{{product.description}}
</div>
<div class="col-3 cartBtn">
<button style="float: right;" (onClick)='addToCart'><i class="bi bi-cart3"></i>&nbsp;&nbsp;Add To Cart</button>
<button style="float: right;" (click)="addToCart(product.discountedPrice)"><i class="bi bi-cart3"></i>&nbsp;&nbsp;Add To Cart</button>
</div>
</div>
<br><br>
<div class="row">
<div class="col-9">
<p style="float: left;">Qty :&nbsp;&nbsp;</p>
<input style="float: left;" type="number" value="1" min="1" #box2 (keyup.enter)="onQuantityEnter(box2.value)">
<input style="float: left;" type="number" value="1" min="1" #box2 (keyup)="onQuantityEnter(box2.value)">
</div>
</div>
<br><br>
<div class="row">
<div class="col-12 heading">
<h3>Reviews</h3>
<hr>
</div>
</div>
<div class="row" *ngFor='let r of reviewDtos'>
<div class="row">
<div class="col-11">
<p class="username">{{r.username}}</p>
</div>
<div class="col-1 text-right">
<p>{{r.rating}} of 5</p>
</div>
</div>
<div class="row">
<div class="col-12">
<p>{{r.reviewText}}</p>
</div>
</div>
<hr>
</div>
</div>

31
ShopifyUI/src/app/components/product-detail/product-detail.component.ts

@ -2,8 +2,10 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Cart } from 'src/app/model/cart.model';
import { Product } from 'src/app/model/product.model';
import { ReviewDto } from 'src/app/model/review.model';
import { CartService } from 'src/app/service/cart.service';
import { ProductService } from 'src/app/service/product.service';
import { ReviewService } from 'src/app/service/review.service';
@Component({
selector: 'app-product-detail',
@ -11,14 +13,15 @@ import { ProductService } from 'src/app/service/product.service';
styleUrls: ['./product-detail.component.css'],
})
export class ProductDetailComponent implements OnInit {
pid:string;
uid:string = "10";
pid:any;
uid:string = "1";
product:Product;
currentRating:any = [];
rating:any = [];
quantity:number;
quantity:number = 1;
cartNo:number = 0;
constructor(private actRouter:ActivatedRoute, private productService:ProductService, private cartService:CartService) { }
reviewDtos: ReviewDto[] = [];
constructor(private actRouter:ActivatedRoute, private productService:ProductService, private cartService:CartService,private reviewService:ReviewService) { }
ngOnInit(): void {
this.cartService.getCartByUser(this.uid).subscribe(data1 => {
@ -37,13 +40,27 @@ export class ProductDetailComponent implements OnInit {
}
console.log(this.rating,this.currentRating);
})
}
addToCart() {
this.reviewService.getReviewsByProduct(this.pid).subscribe(data => {
this.reviewDtos = data;
})
}
onQuantityEnter(value: string) {
this.quantity = +value;
}
addToCart(discountedPrice: number) {
console.log("addtocart")
let cartData:Cart = {
quantity : this.quantity,
price: discountedPrice
}
console.log(cartData)
this.cartService.postCart(cartData,this.uid,this.pid).subscribe(data => {
this.cartService.getCartByUser(this.uid).subscribe(data1 => {
this.cartNo = data1.length;
})
})
}
}

4
ShopifyUI/src/app/components/products/products.component.css

@ -4,7 +4,9 @@
}
.product {
box-shadow: 10px 10px 19px 0px rgba(0,0,0,0.69);
box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-webkit-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-moz-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
margin: 0px auto;
border-radius: 20px;
width: 95%;

2
ShopifyUI/src/app/components/products/products.component.html

@ -36,7 +36,7 @@
</div>
<div class="row">
<div class="col-12">
<img src={{p.imageUrl}} alt={{p.name}} width="30%">
<img src={{p.imageUrl}} alt={{p.name}} width="20%">
</div>
</div>
<div class="row align-items-center">

6
ShopifyUI/src/app/model/review.model.ts

@ -0,0 +1,6 @@
export class ReviewDto {
reviewText:string;
rating:number;
username:string;
product_name:string;
}

7
ShopifyUI/src/app/service/cart.service.ts

@ -8,7 +8,7 @@ import { Cart } from '../model/cart.model';
})
export class CartService {
path:String = "http://localhost:59279/api";
path:String = "http://localhost:59279/api2";
constructor(private httpClent:HttpClient) { }
@ -26,4 +26,9 @@ export class CartService {
let cart_get_api = this.path + "/cart/" + cid;
return this.httpClent.put<any>(cart_get_api,cart);
}
public deleteCartItem(cid:number): Observable<any> {
let cart_delete_api = this.path + "/cart/" + cid;
return this.httpClent.delete<any>(cart_delete_api);
}
}

2
ShopifyUI/src/app/service/product.service.ts

@ -8,7 +8,7 @@ import { Product } from '../model/product.model';
})
export class ProductService {
path:string = "http://localhost:59279/api";
path:string = "http://localhost:59279/api1";
constructor(private httpClient:HttpClient) { }

12
ShopifyUI/src/app/service/review.service.ts

@ -1,9 +1,19 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ReviewDto } from '../model/review.model';
@Injectable({
providedIn: 'root'
})
export class ReviewService {
constructor() { }
path:string = "http://localhost:59279/api3";
constructor(private httpClient:HttpClient) { }
public getReviewsByProduct(pid:string): Observable<ReviewDto[]> {
let review_get_api = this.path + "/review/product?pid=" + pid;
return this.httpClient.get<ReviewDto[]>(review_get_api);
}
}

4
ShopifyUI/src/styles.css

@ -12,6 +12,10 @@ body {
background-color: #1B4F72 !important;
}
.navbar h2 {
font-weight: 700 !important;
}
.navbar a {
padding: 12px;
margin: 0px;

Loading…
Cancel
Save