Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ecommerce-maven
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
ecommerce-maven
Commits
fdecf06b
Commit
fdecf06b
authored
May 12, 2021
by
Christopher Cottier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'AFP-127/add-promotions-to-post-order' into 'master'
Afp 127/add promotions to post order See merge request
!15
parents
5e676eed
4b3273ec
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
112 additions
and
43 deletions
+112
-43
OrderService.java
...main/java/com/nisum/ecomservice/service/OrderService.java
+23
-2
ProductService.java
...in/java/com/nisum/ecomservice/service/ProductService.java
+10
-0
order_history_actions.js
ecom-web/src/actions/order_history_actions.js
+16
-0
order-history.css
ecom-web/src/components/order-history/order-history.css
+6
-0
order-history.jsx
ecom-web/src/components/order-history/order-history.jsx
+17
-9
order_reducer.js
ecom-web/src/reducers/order_reducer.js
+9
-0
order_api_util.js
ecom-web/src/util/order_api_util.js
+31
-32
No files found.
ecom-service/src/main/java/com/nisum/ecomservice/service/OrderService.java
View file @
fdecf06b
...
...
@@ -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
();
...
...
ecom-service/src/main/java/com/nisum/ecomservice/service/ProductService.java
View file @
fdecf06b
...
...
@@ -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
);
}
}
ecom-web/src/actions/order_history_actions.js
0 → 100644
View file @
fdecf06b
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
ecom-web/src/components/order-history/order-history.css
View file @
fdecf06b
...
...
@@ -23,3 +23,9 @@ main {
.order-field
{
font-weight
:
600
;
}
#order-history-header
{
font-size
:
40px
;
text-align
:
center
;
padding
:
10px
;
}
ecom-web/src/components/order-history/order-history.jsx
View file @
fdecf06b
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
}
/>;
...
...
ecom-web/src/reducers/order_reducer.js
View file @
fdecf06b
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
}
...
...
ecom-web/src/util/order_api_util.js
View file @
fdecf06b
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment