Commit af565466 authored by Christopher Cottier's avatar Christopher Cottier

added backend route to fid product by sku, now showing order item picture in order item component

parent 91f52122
...@@ -6,11 +6,9 @@ import com.nisum.ecomservice.service.ProductService; ...@@ -6,11 +6,9 @@ import com.nisum.ecomservice.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RestController @RestController
@RequestMapping("/api") @RequestMapping("/api")
...@@ -38,4 +36,11 @@ public class ProductsController { ...@@ -38,4 +36,11 @@ public class ProductsController {
return ResponseEntity.ok(productService.getAllPromotions()); return ResponseEntity.ok(productService.getAllPromotions());
} }
@GetMapping("/products/{sku}")
public ResponseEntity<Mono<Product>> getProductBySku(@PathVariable String sku) {
return ResponseEntity.ok(productService.getProductBySku(sku));
}
} }
...@@ -13,7 +13,7 @@ const Order = (props) => { ...@@ -13,7 +13,7 @@ const Order = (props) => {
return ( return (
<div className="order"> <div className="order">
<p><span className="order-field">Order ID:</span> {order.id}</p> <p className="order-number">Order #: {order.id}</p>
<p><span className="order-field">Order Status:</span> {order.orderStatus}</p> <p><span className="order-field">Order Status:</span> {order.orderStatus}</p>
<p><span className="order-field">Order Placed:</span> {orderPlaced.getUTCMonth()} <p><span className="order-field">Order Placed:</span> {orderPlaced.getUTCMonth()}
/{orderPlaced.getUTCDay()} /{orderPlaced.getUTCDay()}
......
import React from 'react'; import React, { useEffect,useState } from 'react';
import { fetchProductBySku } from '../../util/product_api_util';
const OrderItem = (props) => { const OrderItem = (props) => {
const {orderItem} = props; const {orderItem} = props;
const {itemName, itemPrice, itemQuantity} = orderItem; const {itemName, itemPrice, itemQuantity, itemSku} = orderItem;
const subTotal = itemQuantity * itemPrice; const subTotal = itemQuantity * itemPrice;
const [fullItemDetails, setFullItemDetails] = useState({});
useEffect(async ()=>{
const item = await fetchProductBySku(itemSku);
setFullItemDetails(item.data);
}, []);
return ( return (
<div className="order-item"> <div className="order-item">
<div className="pic-container">
<img src={fullItemDetails.productImageUrl} />
</div>
<div className="item-details-container">
<p>Item: {itemName}</p> <p>Item: {itemName}</p>
<p>Quantity: {itemQuantity}</p> <p>Quantity: {itemQuantity}</p>
</div>
<div className="item-price-container">
<p>Price Per Unit: ${itemPrice.toFixed(2)}</p> <p>Price Per Unit: ${itemPrice.toFixed(2)}</p>
<p>Subtotal: ${subTotal.toFixed(2)}</p> <p>Subtotal: ${subTotal.toFixed(2)}</p>
</div> </div>
</div>
) )
} }
......
...@@ -6,7 +6,6 @@ main { ...@@ -6,7 +6,6 @@ main {
.order { .order {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
border: 1px solid black;
padding: 20px; padding: 20px;
} }
...@@ -16,12 +15,16 @@ main { ...@@ -16,12 +15,16 @@ main {
} }
.order-item { .order-item {
border: 1px solid gray; display: grid;
padding: 5px; grid-template-columns: 1fr 4fr 1fr;
grid-template-rows: auto;
border: 1px solid red;
width: 100%;
} }
.order-field { .order-number {
font-weight: 600; font-weight: 600;
border-bottom: 1px solid black;
} }
#order-history-header { #order-history-header {
......
...@@ -12,3 +12,7 @@ export const fetchPromotions = () => { ...@@ -12,3 +12,7 @@ export const fetchPromotions = () => {
export const fetchProductsAndPromotions = () => { export const fetchProductsAndPromotions = () => {
return axios.get(`${Config.baseApiUrl}/api/products-and-promos`) return axios.get(`${Config.baseApiUrl}/api/products-and-promos`)
} }
export const fetchProductBySku = (sku) => {
return axios.get(`${Config.baseApiUrl}/api/products/${sku}`)
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment