Commit dba847d4 authored by Shaphen Pangburn's avatar Shaphen Pangburn

Merge branch 'master' of https://gitlab.mynisum.com/ascend/ecommerce-maven...

Merge branch 'master' of https://gitlab.mynisum.com/ascend/ecommerce-maven into show-out-of-stock-for-products-with-no-available-stock
parents 05656a8c 59df5e39
......@@ -8,6 +8,9 @@ import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
......@@ -24,7 +27,6 @@ public class OrderService {
User user = orderRequest.getUser();
Address address = orderRequest.getAddress();
CartPostDTO cart = orderRequest.getCart();
//for each item grab product details from products API
List<Mono<Product>> productsToOrder = cart.getCartItems().stream()
.map(cartItem -> cartItem.getProductRef().getSku())
......@@ -50,8 +52,27 @@ public class OrderService {
orderItem.setItemQuantity(quantity);
return orderItem;
}).flatMap(orderItem -> {
Flux<Promotion> promotionFlux = productService
.getPromotionBySkus(Arrays.asList(orderItem.getItemSku()));
Mono<OrderItem> orderItemMono = promotionFlux
.collectList()
.map(promotionList -> {
System.out.println("Give me promo list");
if (promotionList.size() > 0) {
Promotion promotion = promotionList.get(0);
if (orderItem.getItemQuantity().intValue() >= promotion.getMinimumQuantity().intValue()) {
Float originalPrice = orderItem.getItemPrice();
Float newPrice = originalPrice * ((100 - promotion.getDiscountPercentage()) / 100);
orderItem.setItemPrice(newPrice);
}
}
return orderItem;
});
return orderItemMono;
});
//
//falttens the things
Mono<Mono<Order>> map = orderItems.collectList().map(itemList -> {
OrderSubmission orderSubmission = new OrderSubmission();
......
......@@ -8,6 +8,8 @@ import reactor.core.publisher.Mono;
import com.nisum.ecomservice.model.Promotion;
import reactor.core.publisher.Flux;
import java.util.List;
@Service
public class ProductService {
......@@ -40,4 +42,12 @@ public class ProductService {
.bodyToFlux(Promotion.class);
}
public Flux<Promotion> getPromotionBySkus(List<String> listOfSkus){
return WebClient.create(String.format("%s/api/promos/bulkSearch",AppConfig.getPromoManagementUrl()))
.post()
.bodyValue(listOfSkus)
.retrieve()
.bodyToFlux(Promotion.class);
}
}
......@@ -19,4 +19,4 @@ export const updateUserCart = (updatedCart, userEmail) => dispatch => ApiUtil.up
.then(cart => dispatch(receiveUserCart(cart)));
export const createUserCart = newCart => dispatch => ApiUtil.createCart(newCart)
.then(res => res.json)
\ No newline at end of file
.then(res => res.json)
import OrderHistory from "../components/order-history/order-history";
import { getOrderHistory } from "../util/order_api_util";
export const SET_USER_HISTORY = "SET_USER_HISTORY";
export const dispatchOrderHistory = (userId) => async dispatch =>{
const orderHistory = await getOrderHistory(userId);
return dispatch(orderHistoryAction(orderHistory));
}
const orderHistoryAction = (orderHistory) => (
{
type: SET_USER_HISTORY,
orderHistory
}
)
\ No newline at end of file
import { connect } from 'react-redux';
import HeaderCart from './header-cart';
const mSTP = state => ({
});
const mDTP = dispatch => ({
});
export default connect(mSTP, mDTP)(HeaderCart);
\ No newline at end of file
import React, { Component } from 'react'
import './header.css';
export default class HeaderCart extends Component {
constructor(props) {
super(props)
this.state = {}
}
render() {
return (
<div>
Cart
</div>
)
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import Header from './header';
const mSTP = state => ({
user: state.user
});
const mDTP = dispatch => ({
......
.order-history-nav,
/* .order-history-nav,
.products-nav,
#nav-bar-text,
.cart-nav {
......@@ -6,19 +6,17 @@
padding-top: 11px;
padding-bottom: 10px;
color: white;
}
} */
.nav-home {
color: white;
font-size: 20px;
margin-left: 10px;
.header-nav {
padding-left: 20px;
}
#nav-home-link {
/* #nav-home-link {
margin-bottom: 3px;
} */
.nav-bar-text {
padding-right: 20px;
}
#nav-bar-text {
opacity: 0.6;
cursor: default;
}
\ No newline at end of file
import React, { Component } from 'react'
import Nav from 'react-bootstrap/Nav'
import Navbar from 'react-bootstrap/Navbar'
// import NavDropdown from 'react-bootstrap/NavDropdown'
import NavDropdown from 'react-bootstrap/NavDropdown'
import {NavLink} from 'react-router-dom'
import Session from '../session/session-container'
import HeaderCart from './header-cart-container'
import './header.css';
export default class Header extends Component {
constructor(props) {
super(props)
this.state = {}
super(props)
this.state = {}
}
render() {
let userName
if(!!this.props.user?.currentUser){
userName = this.props.user.currentUser.firstName
}else{
userName = "Guest"
}
return (
<div>
<Navbar collapseOnSelect expand="lg" bg="primary" variant="dark">
<Navbar className = "header-nav" collapseOnSelect expand="sm" bg="light">
<Navbar.Brand>Ascend Ecommerce</Navbar.Brand>
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<NavLink to="/product-market" id="nav-home-link"><span className="nav-home">Ascend Ecommerce</span></NavLink>
<Navbar.Collapse id="responsive-navbar-nav">
<Nav >
<Navbar.Text id="nav-bar-text">
Hello Guest!
</Navbar.Text>
<Nav className="mr-auto">
<Nav.Link to="/product-market" id="nav-home-link">Home</Nav.Link>
<Nav.Link to="/product-market">Products</Nav.Link>
</Nav>
<NavLink to="/product-market"><span className="products-nav">Products</span></NavLink>
<NavLink to="/orders"><span className="order-history-nav">Order History</span></NavLink>
<NavLink to="/cart"><span className="cart-nav">Cart</span></NavLink>
<Nav className="ms-auto">
<Session />
{!this.props.user?.currentUser ?
<Navbar.Text className="nav-bar-text">Hello Guest</Navbar.Text> :
<NavDropdown className="nav-bar-text" title={"Hello "+userName} id="collasible-nav-dropdown">
<NavDropdown.Item ><NavLink to="/orders">Order History</NavLink></NavDropdown.Item>
</NavDropdown>
}
<Session className="nav-bar-text"/>
<HeaderCart className="nav-bar-text"/>
</Nav>
</Navbar.Collapse>
</Navbar>
......
......@@ -23,3 +23,9 @@ main {
.order-field {
font-weight: 600;
}
#order-history-header {
font-size: 40px;
text-align: center;
padding: 10px;
}
import React, { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux';
import { dispatchOrderHistory } from '../../actions/order_history_actions';
import { getOrderHistory } from '../../util/order_api_util';
import Order from './Order';
......@@ -6,20 +8,26 @@ import './order-history.css'
const OrderHistory = () => {
const [orderHistory, setOrderHistory] = useState([]);
const [callMade, setCallMade] = useState(false);
const dispatch = useDispatch();
const user = useSelector(state => state.user);
const {orderHistory} = useSelector(state => state.orderStatus)
//const [callMade, setCallMade] = useState(false);
useEffect( async () => {
if (callMade) return;
const userHistory = await getOrderHistory('e-com-test-id2'); //insert user id from user details stored in redux
setOrderHistory(userHistory);
setCallMade(true);
});
if (!user) return;
if (!user.currentUser) return;
dispatch(dispatchOrderHistory(user.currentUser.userId));
//setCallMade(true);
}, [user]);
return (
<main>
<h1>Order History</h1>
<h1 id="order-history-header">Order History</h1>
{user === null ? (
<div>Please login to place orders!</div>
) : null}
<div id="orders">
{orderHistory.map(order => {
return <Order order={order}/>;
......
......@@ -15,4 +15,4 @@ const cartReducer = (state = initialState, action) => {
}
}
export default cartReducer;
\ No newline at end of file
export default cartReducer;
import { SET_USER_HISTORY } from '../actions/order_history_actions';
import { LOGOUT_USER } from '../actions/session_actions';
import {SEND_USER_ORDER} from './../actions/checkout_actions'
const initialState = {
orderResponse: {},
orderHistory: []
}
const orderReducer = (prevState = initialState, action) => {
......@@ -13,6 +16,12 @@ const orderReducer = (prevState = initialState, action) => {
nextState.orderResponse = action.payload
return nextState
case SET_USER_HISTORY:
nextState.orderHistory = action.orderHistory;
return nextState;
case LOGOUT_USER:
nextState.orderHistory = [];
return nextState;
default:
return nextState
}
......
......@@ -2,37 +2,36 @@ import Config from "../config";
export const getOrderHistory = async (userId) => {
//This is what we will return once our oder history API is operational
// const res = await fetch(`${Config.orderHistoryApiUrlMethod(userId)}`);
// const orders = await res.json();
// return orders;
const res = await fetch(`${Config.orderHistoryApiUrlMethod(userId)}`);
const orders = await res.json();
return orders;
return (
[
{
id: "609968a89cc32e1ef8208e8b",
orderTrackingCode: "N/A",
orderStatus: "RECEIVED",
orderCreatedAt: 1620666536727,
orderUpdatedAt: 1620666536727,
customerId: "e-com-test-id2",
customerEmailAddress: "test@test.test",
orderItems: [
{
itemId: "AFP-989",
itemName: "this item",
itemSku: "AFP-989",
itemQuantity: 2,
itemPrice: 14.0
}
],
customerAddress: {
street: "Grand",
city: "chicago",
state: "IL",
zip: "90210"
}
}
]
)
// return (
// [
// {
// id: "609968a89cc32e1ef8208e8b",
// orderTrackingCode: "N/A",
// orderStatus: "RECEIVED",
// orderCreatedAt: 1620666536727,
// orderUpdatedAt: 1620666536727,
// customerId: "e-com-test-id2",
// customerEmailAddress: "test@test.test",
// orderItems: [
// {
// itemId: "AFP-989",
// itemName: "this item",
// itemSku: "AFP-989",
// itemQuantity: 2,
// itemPrice: 14.0
// }
// ],
// customerAddress: {
// street: "Grand",
// city: "chicago",
// state: "IL",
// zip: "90210"
// }
// }
// ]
// )
}
\ 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