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
3132ce08
Commit
3132ce08
authored
May 07, 2021
by
Julius Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edit promo is completed
parent
c2cc691d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
3 deletions
+31
-3
PromotionsController.java
...um/ascend/promotions/controller/PromotionsController.java
+5
-3
PromotionRepository.java
...sum/ascend/promotions/repository/PromotionRepository.java
+2
-0
PromotionService.java
...com/nisum/ascend/promotions/service/PromotionService.java
+10
-0
PromotionsControllerTest.java
...scend/promotions/controller/PromotionsControllerTest.java
+14
-0
No files found.
src/main/java/com/nisum/ascend/promotions/controller/PromotionsController.java
View file @
3132ce08
...
...
@@ -46,11 +46,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/repository/PromotionRepository.java
View file @
3132ce08
...
...
@@ -5,8 +5,10 @@ import com.nisum.ascend.promotions.model.Promotion;
import
org.springframework.data.mongodb.repository.ReactiveMongoRepository
;
import
org.springframework.stereotype.Repository
;
import
reactor.core.publisher.Flux
;
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 @
3132ce08
...
...
@@ -25,4 +25,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 @
3132ce08
...
...
@@ -99,4 +99,18 @@ 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
);
}
}
\ 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