Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
inventory-service
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
inventory-service
Commits
39693637
Commit
39693637
authored
May 12, 2021
by
John Lam
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into AFP-66-kafka-consumers
parents
6679afe8
f6ac5a41
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
64 deletions
+52
-64
deployment.yml
deployment.yml
+37
-0
ProductController.java
.../nisum/ascend/inventory/controller/ProductController.java
+5
-6
ProductDto.java
src/main/java/com/nisum/ascend/inventory/dto/ProductDto.java
+0
-23
PromotionDto.java
...ain/java/com/nisum/ascend/inventory/dto/PromotionDto.java
+0
-15
Product.java
src/main/java/com/nisum/ascend/inventory/model/Product.java
+2
-0
ProductService.java
...va/com/nisum/ascend/inventory/service/ProductService.java
+8
-20
No files found.
deployment.yml
0 → 100644
View file @
39693637
apiVersion
:
apps/v1
kind
:
Deployment
metadata
:
name
:
afp-products-deployment
spec
:
replicas
:
2
selector
:
matchLabels
:
app
:
afp-products
template
:
metadata
:
labels
:
app
:
afp-products
spec
:
containers
:
-
name
:
afp-products-container
image
:
nexus.mynisum.com/afp-products:latest
imagePullPolicy
:
Always
ports
:
-
containerPort
:
8080
env
:
-
name
:
PORT
value
:
"
8080"
imagePullSecrets
:
-
name
:
registry-creds
---
apiVersion
:
v1
kind
:
Service
metadata
:
name
:
afp-products-service
spec
:
type
:
LoadBalancer
ports
:
-
port
:
8080
targetPort
:
8080
selector
:
app
:
afp-products
\ No newline at end of file
src/main/java/com/nisum/ascend/inventory/controller/ProductController.java
View file @
39693637
package
com
.
nisum
.
ascend
.
inventory
.
controller
;
import
com.nisum.ascend.inventory.dto.ProductDto
;
import
com.nisum.ascend.inventory.exception.ResourceAlreadyExistsException
;
import
com.nisum.ascend.inventory.model.Product
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -37,26 +36,26 @@ public class ProductController {
}
@GetMapping
(
"/{sku}"
)
public
ResponseEntity
<
Mono
<
Product
Dto
>>
getProductBySku
(
@PathVariable
String
sku
)
{
Mono
<
Product
Dto
>
monoProd
=
productService
.
getProductBySku
(
sku
);
public
ResponseEntity
<
Mono
<
Product
>>
getProductBySku
(
@PathVariable
String
sku
)
{
Mono
<
Product
>
monoProd
=
productService
.
getProductBySku
(
sku
);
HttpStatus
status
=
monoProd
!=
null
?
HttpStatus
.
OK
:
HttpStatus
.
NOT_FOUND
;
return
new
ResponseEntity
<>(
monoProd
,
status
);
}
@GetMapping
()
public
ResponseEntity
<
Flux
<
Product
Dto
>>
getAllProducts
()
{
public
ResponseEntity
<
Flux
<
Product
>>
getAllProducts
()
{
return
ResponseEntity
.
ok
(
productService
.
findAllProducts
());
}
@PutMapping
(
"/{sku}"
)
public
Mono
<
ResponseEntity
<
Product
Dto
>>
updateProduct
(
@PathVariable
String
sku
,
@RequestBody
Product
product
){
public
Mono
<
ResponseEntity
<
Product
>>
updateProduct
(
@PathVariable
String
sku
,
@RequestBody
Product
product
){
return
productService
.
updateProductBySku
(
sku
,
product
)
.
map
(
updatedProduct
->
ResponseEntity
.
ok
(
updatedProduct
))
.
defaultIfEmpty
(
ResponseEntity
.
badRequest
().
build
());
}
@PostMapping
(
""
)
public
Mono
<
Product
Dto
>
postProduct
(
@RequestBody
Product
product
)
{
public
Mono
<
Product
>
postProduct
(
@RequestBody
Product
product
)
{
return
productService
.
createProduct
(
product
).
onErrorMap
(
throwable
->
new
ResourceAlreadyExistsException
());
}
}
\ No newline at end of file
src/main/java/com/nisum/ascend/inventory/dto/ProductDto.java
deleted
100644 → 0
View file @
6679afe8
package
com
.
nisum
.
ascend
.
inventory
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
com.nisum.ascend.inventory.model.Product
;
import
java.util.ArrayList
;
import
java.util.List
;
@Getter
@AllArgsConstructor
public
class
ProductDto
{
private
String
sku
;
private
String
upc
;
private
String
productName
;
private
String
productDescription
;
private
float
price
;
private
String
productImageUrl
;
private
String
brand
;
private
String
category
;
private
int
stock
;
private
List
<
PromotionDto
>
promotions
;
}
src/main/java/com/nisum/ascend/inventory/dto/PromotionDto.java
deleted
100644 → 0
View file @
6679afe8
package
com
.
nisum
.
ascend
.
inventory
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@Getter
@AllArgsConstructor
public
class
PromotionDto
{
private
String
promotionId
;
private
String
productSku
;
private
float
discountPercentage
;
private
int
minimumQuantity
;
public
PromotionDto
()
{}
}
src/main/java/com/nisum/ascend/inventory/model/Product.java
View file @
39693637
...
...
@@ -20,6 +20,7 @@ public class Product {
private
float
price
;
private
int
availableStock
;
private
int
blockedStock
;
private
int
fulfilledStock
;
private
String
productImageUrl
;
private
String
brand
;
private
String
category
;
...
...
@@ -34,6 +35,7 @@ public class Product {
this
.
price
=
price
;
this
.
availableStock
=
availableStock
;
this
.
blockedStock
=
0
;
this
.
fulfilledStock
=
0
;
this
.
productImageUrl
=
productImageUrl
;
this
.
brand
=
brand
;
this
.
category
=
category
;
...
...
src/main/java/com/nisum/ascend/inventory/service/ProductService.java
View file @
39693637
package
com
.
nisum
.
ascend
.
inventory
.
service
;
import
com.nisum.ascend.inventory.dto.ProductDto
;
import
com.nisum.ascend.inventory.dto.PromotionDto
;
import
com.nisum.ascend.inventory.exception.ResourceNotFoundException
;
import
com.nisum.ascend.inventory.model.Product
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -19,35 +18,25 @@ public class ProductService {
@Autowired
ProductRepository
productRepository
;
public
ProductDto
generateDtoFromProduct
(
Product
product
)
{
// TODO: Fetch the product's promotion from the Promotions com.nisum.ascend.inventory.service
List
<
PromotionDto
>
promotions
=
new
ArrayList
<>();
return
new
ProductDto
(
product
.
getSku
(),
product
.
getUpc
(),
product
.
getProductName
(),
product
.
getProductDescription
(),
product
.
getPrice
(),
product
.
getProductImageUrl
(),
product
.
getBrand
(),
product
.
getCategory
(),
product
.
getAvailableStock
(),
promotions
);
}
public
Mono
<
ProductDto
>
removeProductBySku
(
String
sku
)
{
public
Mono
<
Product
>
removeProductBySku
(
String
sku
)
{
return
productRepository
.
findBySku
(
sku
)
.
flatMap
(
existingProduct
->
productRepository
.
delete
(
existingProduct
)
.
then
(
Mono
.
just
(
existingProduct
)))
.
map
(
this
::
generateDtoFromProduct
)
.
switchIfEmpty
(
Mono
.
error
(
new
ResourceNotFoundException
(
HttpStatus
.
NOT_FOUND
,
"Product Not Found"
)));
}
public
Mono
<
Product
Dto
>
getProductBySku
(
String
sku
){
public
Mono
<
Product
>
getProductBySku
(
String
sku
){
return
productRepository
.
findBySku
(
sku
)
.
map
(
this
::
generateDtoFromProduct
)
.
switchIfEmpty
(
Mono
.
error
(
new
ResourceNotFoundException
(
HttpStatus
.
NOT_FOUND
,
"product not found"
)));
}
public
Flux
<
ProductDto
>
findAllProducts
()
{
return
productRepository
.
findAll
()
.
map
(
this
::
generateDtoFromProduct
);
public
Flux
<
Product
>
findAllProducts
()
{
return
productRepository
.
findAll
();
}
public
Mono
<
Product
Dto
>
updateProductBySku
(
String
sku
,
Product
product
){
public
Mono
<
Product
>
updateProductBySku
(
String
sku
,
Product
product
){
return
productRepository
.
findBySku
(
sku
)
.
flatMap
(
dbProduct
->
{
dbProduct
.
setUpc
(
product
.
getUpc
());
...
...
@@ -59,12 +48,11 @@ public class ProductService {
dbProduct
.
setAvailableStock
(
product
.
getAvailableStock
());
dbProduct
.
setProductImageUrl
(
product
.
getProductImageUrl
());
return
productRepository
.
save
(
dbProduct
);
})
.
map
(
this
::
generateDtoFromProduct
)
;
});
}
public
Mono
<
ProductDto
>
createProduct
(
Product
product
)
{
return
productRepository
.
save
(
product
)
.
map
(
this
::
generateDtoFromProduct
);
public
Mono
<
Product
>
createProduct
(
Product
product
)
{
return
productRepository
.
save
(
product
);
}
}
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