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
4b7f1cf5
Commit
4b7f1cf5
authored
May 10, 2021
by
Sumaiyya Burney
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'AFP-62' into 'dev'
edit promo is completed See merge request
!9
parents
f80b22ac
297582f7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
15 deletions
+32
-15
PromotionsController.java
...um/ascend/promotions/controller/PromotionsController.java
+5
-3
RestWebExceptionHandler.java
.../ascend/promotions/exception/RestWebExceptionHandler.java
+0
-11
PromotionRepository.java
...sum/ascend/promotions/repository/PromotionRepository.java
+0
-1
PromotionService.java
...com/nisum/ascend/promotions/service/PromotionService.java
+10
-0
PromotionsControllerTest.java
...scend/promotions/controller/PromotionsControllerTest.java
+17
-0
No files found.
src/main/java/com/nisum/ascend/promotions/controller/PromotionsController.java
View file @
4b7f1cf5
...
...
@@ -49,11 +49,13 @@ public class PromotionsController {
}
@PutMapping
(
"/{promoId}"
)
public
Mono
<
ResponseEntity
<
PromotionDto
>>
updatePromotionById
(
@PathVariable
String
promoId
,
@RequestBody
Promotion
newPromotion
){
//TODO: update promotion
return
null
;
public
Mono
<
ResponseEntity
<
PromotionDto
>>
updatePromotionById
(
@PathVariable
(
"promoId"
)
String
promoId
,
@RequestBody
Promotion
newPromotion
){
return
promotionService
.
updatePromotion
(
promoId
,
newPromotion
)
.
map
(
updatedProduct
->
ResponseEntity
.
ok
(
updatedProduct
))
.
defaultIfEmpty
(
ResponseEntity
.
badRequest
().
build
());
}
@DeleteMapping
(
"/{promoId}"
)
public
Mono
<
ResponseEntity
<
PromotionDto
>>
deletePromotionById
(
@PathVariable
String
promoId
){
//TODO: delete promotion
...
...
src/main/java/com/nisum/ascend/promotions/exception/RestWebExceptionHandler.java
View file @
4b7f1cf5
...
...
@@ -25,16 +25,6 @@ class RestWebExceptionHandler implements WebExceptionHandler {
// marks the response as complete and forbids writing to it
return
exchange
.
getResponse
().
writeWith
(
Flux
.
just
(
buffer
));
}
return
Mono
.
error
(
ex
);
}
}
@Component
@Order
(-
2
)
class
RestWebExceptionHandler
implements
WebExceptionHandler
{
@Override
public
Mono
<
Void
>
handle
(
ServerWebExchange
exchange
,
Throwable
ex
)
{
if
(
ex
instanceof
PromotionAlreadyExistsException
)
{
exchange
.
getResponse
().
setStatusCode
(
HttpStatus
.
NOT_ACCEPTABLE
);
...
...
@@ -42,5 +32,4 @@ class RestWebExceptionHandler implements WebExceptionHandler {
}
return
Mono
.
error
(
ex
);
}
}
src/main/java/com/nisum/ascend/promotions/repository/PromotionRepository.java
View file @
4b7f1cf5
...
...
@@ -10,6 +10,5 @@ import reactor.core.publisher.Mono;
@Repository
public
interface
PromotionRepository
extends
ReactiveMongoRepository
<
Promotion
,
String
>
{
Flux
<
Promotion
>
findByProductSku
(
String
sku
);
Mono
<
Promotion
>
findByPromotionId
(
String
promoId
);
}
src/main/java/com/nisum/ascend/promotions/service/PromotionService.java
View file @
4b7f1cf5
...
...
@@ -35,4 +35,14 @@ public class PromotionService {
public
Mono
<
PromotionDto
>
createPromotion
(
Promotion
promotion
){
return
promotionRepository
.
save
(
promotion
).
map
(
PromotionDto:
:
generateDtoFromPromotion
);
}
public
Mono
<
PromotionDto
>
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
);
});
}
}
src/test/java/com/nisum/ascend/promotions/controller/PromotionsControllerTest.java
View file @
4b7f1cf5
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
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -62,7 +63,9 @@ class PromotionsControllerTest {
.
expectHeader
().
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
expectBody
()
.
jsonPath
(
"promotionId"
,
"0003"
);
}
@Test
void
createPromotion
(){
Promotion
promotion
=
new
Promotion
(
"50OFF"
,
"SH1234"
,
(
float
)
0.5
,
5
);
webTestClient
.
post
().
uri
(
"/api/promos"
)
...
...
@@ -111,6 +114,20 @@ class PromotionsControllerTest {
promos
.
forEach
(
p
->
assertEquals
(
skuWithMultiplePromos
,
p
.
getProductSku
()));
});
}
@Test
void
editPromotion
(){
Promotion
promotion
=
new
Promotion
(
"0003"
,
"1000"
,(
float
)
.
5
,
1
);
webTestClient
.
put
()
.
uri
(
"/api/promos/0003"
)
.
contentType
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
accept
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
body
(
Mono
.
just
(
promotion
),
Promotion
.
class
)
.
exchange
()
.
expectStatus
().
isOk
()
.
expectBody
()
.
jsonPath
(
"$.minimumQuantity"
).
isEqualTo
(
1
);
}
@Test
public
void
bulkSearchTest
(){
...
...
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