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
3a54dfd3
Commit
3a54dfd3
authored
May 11, 2021
by
Christopher Cottier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debugging with sai
parent
da9a9de0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
OrderService.java
...main/java/com/nisum/ecomservice/service/OrderService.java
+21
-2
ProductService.java
...in/java/com/nisum/ecomservice/service/ProductService.java
+10
-0
No files found.
ecom-service/src/main/java/com/nisum/ecomservice/service/OrderService.java
View file @
3a54dfd3
...
...
@@ -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,8 +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,6 +51,24 @@ public class OrderService {
orderItem
.
setItemQuantity
(
quantity
);
//set promotion if applicable
Flux
<
Promotion
>
promotionFlux
=
productService
.
getPromotionBySkus
(
Arrays
.
asList
(
orderItem
.
getItemSku
()));
promotionFlux
.
collectList
()
.
map
(
promotionList
->
{
System
.
out
.
println
(
"Give me promo list"
);
if
(
promotionList
.
size
()
==
0
)
{
return
promotionList
;}
Promotion
promotion
=
promotionList
.
get
(
0
);
if
(
orderItem
.
getItemQuantity
().
intValue
()
>=
promotion
.
getMinimumQuantity
().
intValue
())
{
Float
originalPrice
=
orderItem
.
getItemPrice
();
Float
newPrice
=
originalPrice
*
(
promotion
.
getDiscountPercentage
()
/
100
);
orderItem
.
setItemPrice
(
newPrice
);
}
return
promotion
;
}).
subscribe
();
return
orderItem
;
});
//
...
...
ecom-service/src/main/java/com/nisum/ecomservice/service/ProductService.java
View file @
3a54dfd3
...
...
@@ -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
);
}
}
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