Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
promotions-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
promotions-service
Commits
90afae02
Commit
90afae02
authored
May 12, 2021
by
Ben Anderson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed DTO
parent
2164ca44
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
52 deletions
+26
-52
PromotionsController.java
...um/ascend/promotions/controller/PromotionsController.java
+7
-9
PromotionDto.java
...in/java/com/nisum/ascend/promotions/dto/PromotionDto.java
+0
-21
PromotionService.java
...com/nisum/ascend/promotions/service/PromotionService.java
+11
-13
PromotionsControllerTest.java
...scend/promotions/controller/PromotionsControllerTest.java
+8
-9
No files found.
src/main/java/com/nisum/ascend/promotions/controller/PromotionsController.java
View file @
90afae02
package
com
.
nisum
.
ascend
.
promotions
.
controller
;
import
com.nisum.ascend.promotions.dto.PromotionDto
;
import
com.nisum.ascend.promotions.exception.PromotionNotFoundException
;
import
com.nisum.ascend.promotions.exception.PromotionAlreadyExistsException
;
import
com.nisum.ascend.promotions.model.Promotion
;
import
com.nisum.ascend.promotions.repository.PromotionRepository
;
import
com.nisum.ascend.promotions.service.PromotionService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -25,7 +23,7 @@ public class PromotionsController {
PromotionService
promotionService
;
@GetMapping
()
public
ResponseEntity
<
Flux
<
Promotion
Dto
>>
getAllPromotions
(
@RequestParam
(
required
=
false
)
String
sku
){
public
ResponseEntity
<
Flux
<
Promotion
>>
getAllPromotions
(
@RequestParam
(
required
=
false
)
String
sku
){
if
(
sku
!=
null
){
return
ResponseEntity
.
ok
(
promotionService
.
findPromotionsByProductSku
(
sku
));
}
...
...
@@ -33,27 +31,27 @@ public class PromotionsController {
}
@GetMapping
(
"/{id}"
)
public
ResponseEntity
<
Mono
<
Promotion
Dto
>>
getPromotionById
(
@PathVariable
String
id
){
Mono
<
Promotion
Dto
>
responseData
=
promotionService
public
ResponseEntity
<
Mono
<
Promotion
>>
getPromotionById
(
@PathVariable
String
id
){
Mono
<
Promotion
>
responseData
=
promotionService
.
findPromoById
(
id
)
.
switchIfEmpty
(
Mono
.
error
(
new
PromotionNotFoundException
(
id
)));
return
ResponseEntity
.
ok
().
body
(
responseData
);
}
@PostMapping
(
""
)
public
ResponseEntity
<
Mono
<
Promotion
Dto
>>
createPromotion
(
@RequestBody
Promotion
newPromotion
){
Mono
<
Promotion
Dto
>
responseData
=
promotionService
.
createPromotion
(
newPromotion
)
public
ResponseEntity
<
Mono
<
Promotion
>>
createPromotion
(
@RequestBody
Promotion
newPromotion
){
Mono
<
Promotion
>
responseData
=
promotionService
.
createPromotion
(
newPromotion
)
.
onErrorResume
(
throwable
->
Mono
.
error
(
new
PromotionAlreadyExistsException
()));
return
ResponseEntity
.
ok
(
responseData
);
}
@PostMapping
(
"/bulkSearch"
)
public
ResponseEntity
<
Flux
<
Promotion
Dto
>>
bulkSearchPromotionsByItemSku
(
@RequestBody
List
<
String
>
skus
){
public
ResponseEntity
<
Flux
<
Promotion
>>
bulkSearchPromotionsByItemSku
(
@RequestBody
List
<
String
>
skus
){
return
ResponseEntity
.
ok
(
promotionService
.
bulkSearchSku
(
skus
));
}
@PutMapping
(
"/{promoId}"
)
public
Mono
<
ResponseEntity
<
Promotion
Dto
>>
updatePromotionById
(
@PathVariable
(
"promoId"
)
String
promoId
,
@RequestBody
Promotion
newPromotion
){
public
Mono
<
ResponseEntity
<
Promotion
>>
updatePromotionById
(
@PathVariable
(
"promoId"
)
String
promoId
,
@RequestBody
Promotion
newPromotion
){
return
promotionService
.
updatePromotion
(
promoId
,
newPromotion
)
.
map
(
updatedProduct
->
ResponseEntity
.
ok
(
updatedProduct
))
.
defaultIfEmpty
(
ResponseEntity
.
badRequest
().
build
());
...
...
src/main/java/com/nisum/ascend/promotions/dto/PromotionDto.java
deleted
100644 → 0
View file @
2164ca44
package
com
.
nisum
.
ascend
.
promotions
.
dto
;
import
com.nisum.ascend.promotions.model.Promotion
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
@Getter
@AllArgsConstructor
public
class
PromotionDto
{
private
String
promotionId
;
private
String
productSku
;
private
float
discountPercentage
;
private
int
minimumQuantity
;
public
static
PromotionDto
generateDtoFromPromotion
(
Promotion
p
)
{
return
new
PromotionDto
(
p
.
getPromotionId
(),
p
.
getProductSku
(),
p
.
getDiscountPercentage
(),
p
.
getMinimumQuantity
());
}
public
PromotionDto
()
{}
}
src/main/java/com/nisum/ascend/promotions/service/PromotionService.java
View file @
90afae02
package
com
.
nisum
.
ascend
.
promotions
.
service
;
import
com.nisum.ascend.promotions.dto.PromotionDto
;
import
com.nisum.ascend.promotions.exception.ResourceNotFoundException
;
import
com.nisum.ascend.promotions.model.Promotion
;
import
com.nisum.ascend.promotions.repository.PromotionRepository
;
...
...
@@ -17,33 +16,32 @@ public class PromotionService {
@Autowired
PromotionRepository
promotionRepository
;
public
Flux
<
Promotion
Dto
>
findAll
(){
return
promotionRepository
.
findAll
()
.
map
(
PromotionDto:
:
generateDtoFromPromotion
)
;
public
Flux
<
Promotion
>
findAll
(){
return
promotionRepository
.
findAll
();
}
public
Mono
<
PromotionDto
>
findPromoById
(
String
promoId
)
{
return
promotionRepository
.
findByPromotionId
(
promoId
)
.
map
(
PromotionDto:
:
generateDtoFromPromotion
);
public
Mono
<
Promotion
>
findPromoById
(
String
promoId
)
{
return
promotionRepository
.
findByPromotionId
(
promoId
);
}
public
Flux
<
Promotion
Dto
>
findPromotionsByProductSku
(
String
sku
){
return
promotionRepository
.
findByProductSku
(
sku
)
.
map
(
PromotionDto:
:
generateDtoFromPromotion
)
;
public
Flux
<
Promotion
>
findPromotionsByProductSku
(
String
sku
){
return
promotionRepository
.
findByProductSku
(
sku
);
}
public
Flux
<
Promotion
Dto
>
bulkSearchSku
(
List
<
String
>
skus
){
public
Flux
<
Promotion
>
bulkSearchSku
(
List
<
String
>
skus
){
return
Flux
.
fromIterable
(
skus
).
flatMap
(
sku
->
findPromotionsByProductSku
(
sku
));
}
public
Mono
<
Promotion
Dto
>
createPromotion
(
Promotion
promotion
){
return
promotionRepository
.
save
(
promotion
)
.
map
(
PromotionDto:
:
generateDtoFromPromotion
)
;
public
Mono
<
Promotion
>
createPromotion
(
Promotion
promotion
){
return
promotionRepository
.
save
(
promotion
);
}
public
Mono
<
Promotion
Dto
>
updatePromotion
(
String
promoId
,
Promotion
promotion
){
public
Mono
<
Promotion
>
updatePromotion
(
String
promoId
,
Promotion
promotion
){
return
promotionRepository
.
findByPromotionId
(
promoId
)
.
flatMap
(
promo
->{
promo
.
setDiscountPercentage
(
promotion
.
getDiscountPercentage
());
promo
.
setProductSku
(
promotion
.
getProductSku
());
promo
.
setMinimumQuantity
(
promotion
.
getMinimumQuantity
());
return
promotionRepository
.
save
(
promo
)
.
map
(
PromotionDto:
:
generateDtoFromPromotion
)
;
return
promotionRepository
.
save
(
promo
);
});
}
...
...
src/test/java/com/nisum/ascend/promotions/controller/PromotionsControllerTest.java
View file @
90afae02
package
com
.
nisum
.
ascend
.
promotions
.
controller
;
import
com.nisum.ascend.promotions.dto.PromotionDto
;
import
com.nisum.ascend.promotions.model.Promotion
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.jupiter.api.BeforeEach
;
...
...
@@ -44,9 +43,9 @@ class PromotionsControllerTest {
webTestClient
.
get
().
uri
(
"/api/promos"
).
exchange
()
.
expectStatus
().
isOk
()
.
expectHeader
().
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
expectBodyList
(
Promotion
Dto
.
class
)
.
expectBodyList
(
Promotion
.
class
)
.
consumeWith
(
promo
->{
List
<
Promotion
Dto
>
promos
=
promo
.
getResponseBody
();
List
<
Promotion
>
promos
=
promo
.
getResponseBody
();
assert
promos
!=
null
;
promos
.
forEach
(
p
->{
assertNotNull
(
p
.
getPromotionId
());
...
...
@@ -90,10 +89,10 @@ class PromotionsControllerTest {
.
exchange
()
.
expectStatus
().
isOk
()
.
expectHeader
().
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
expectBodyList
(
Promotion
Dto
.
class
)
.
expectBodyList
(
Promotion
.
class
)
.
hasSize
(
1
)
.
consumeWith
(
promo
->{
List
<
Promotion
Dto
>
promos
=
promo
.
getResponseBody
();
List
<
Promotion
>
promos
=
promo
.
getResponseBody
();
assert
promos
!=
null
;
promos
.
forEach
(
p
->
assertEquals
(
skuWithOnePromo
,
p
.
getProductSku
()));
});
...
...
@@ -106,10 +105,10 @@ class PromotionsControllerTest {
.
exchange
()
.
expectStatus
().
isOk
()
.
expectHeader
().
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
expectBodyList
(
Promotion
Dto
.
class
)
.
expectBodyList
(
Promotion
.
class
)
.
hasSize
(
2
)
.
consumeWith
(
promo
->{
List
<
Promotion
Dto
>
promos
=
promo
.
getResponseBody
();
List
<
Promotion
>
promos
=
promo
.
getResponseBody
();
assert
promos
!=
null
;
promos
.
forEach
(
p
->
assertEquals
(
skuWithMultiplePromos
,
p
.
getProductSku
()));
});
...
...
@@ -168,9 +167,9 @@ class PromotionsControllerTest {
.
body
(
Mono
.
just
(
skus
),
List
.
class
)
.
exchange
()
.
expectStatus
().
isOk
()
.
expectBodyList
(
Promotion
Dto
.
class
)
.
expectBodyList
(
Promotion
.
class
)
.
consumeWith
(
promo
->{
List
<
Promotion
Dto
>
promos
=
promo
.
getResponseBody
();
List
<
Promotion
>
promos
=
promo
.
getResponseBody
();
assert
promos
!=
null
;
promos
.
forEach
(
p
->
{
String
sku
=
p
.
getProductSku
();
...
...
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