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
057c3619
Commit
057c3619
authored
May 07, 2021
by
Khai Yuan Liew
Browse files
Options
Browse Files
Download
Plain Diff
[AFP-60] Fixed merge conflict
parents
5d69c51e
c2cc691d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
14 deletions
+56
-14
PromotionsController.java
...um/ascend/promotions/controller/PromotionsController.java
+4
-4
PromotionAlreadyExistsException.java
...promotions/exception/PromotionAlreadyExistsException.java
+11
-0
RestWebExceptionHandler.java
.../ascend/promotions/exception/RestWebExceptionHandler.java
+23
-0
PromotionService.java
...com/nisum/ascend/promotions/service/PromotionService.java
+6
-9
PromotionsControllerTest.java
...scend/promotions/controller/PromotionsControllerTest.java
+12
-1
No files found.
src/main/java/com/nisum/ascend/promotions/controller/PromotionsController.java
View file @
057c3619
package
com
.
nisum
.
ascend
.
promotions
.
controller
;
import
com.nisum.ascend.promotions.dto.PromotionDto
;
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
;
...
...
@@ -34,10 +35,9 @@ public class PromotionsController {
return
null
;
}
@PostMapping
()
public
Mono
<
ResponseEntity
<
PromotionDto
>>
createPromotion
(
@RequestBody
Promotion
newPromotion
){
//TODO: create promotion
return
null
;
@PostMapping
(
""
)
public
Mono
<
PromotionDto
>
createPromotion
(
@RequestBody
Promotion
newPromotion
){
return
promotionService
.
createPromotion
(
newPromotion
).
onErrorMap
(
throwable
->
new
PromotionAlreadyExistsException
());
}
@PostMapping
(
"/bulkSearch"
)
...
...
src/main/java/com/nisum/ascend/promotions/exception/PromotionAlreadyExistsException.java
0 → 100644
View file @
057c3619
package
com
.
nisum
.
ascend
.
promotions
.
exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
@ResponseStatus
(
value
=
HttpStatus
.
NOT_ACCEPTABLE
)
public
class
PromotionAlreadyExistsException
extends
RuntimeException
{
public
PromotionAlreadyExistsException
(){
super
(
"promotion already existed"
);
}
}
src/main/java/com/nisum/ascend/promotions/exception/RestWebExceptionHandler.java
0 → 100644
View file @
057c3619
package
com
.
nisum
.
ascend
.
promotions
.
exception
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.WebExceptionHandler
;
import
reactor.core.publisher.Mono
;
@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
);
return
exchange
.
getResponse
().
setComplete
();
}
return
Mono
.
error
(
ex
);
}
}
src/main/java/com/nisum/ascend/promotions/service/PromotionService.java
View file @
057c3619
package
com
.
nisum
.
ascend
.
promotions
.
service
;
import
com.nisum.ascend.promotions.dto.PromotionDto
;
import
com.nisum.ascend.promotions.model.Promotion
;
import
com.nisum.ascend.promotions.repository.PromotionRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.reactive.function.BodyInserters
;
import
reactor.core.publisher.Flux
;
import
reactor.core.scheduler.Schedulers
;
import
java.util.List
;
import
static
org
.
springframework
.
http
.
ResponseEntity
.
notFound
;
import
static
org
.
springframework
.
http
.
ResponseEntity
.
ok
;
import
reactor.core.publisher.Mono
;
@Service
public
class
PromotionService
{
...
...
@@ -28,9 +24,10 @@ public class PromotionService {
}
public
Flux
<
PromotionDto
>
bulkSearchSku
(
List
<
String
>
skus
){
return
Flux
.
fromIterable
(
skus
)
.
flatMap
(
sku
->
findPromotionsByProductSku
(
sku
));
return
Flux
.
fromIterable
(
skus
).
flatMap
(
sku
->
findPromotionsByProductSku
(
sku
));
}
public
Mono
<
PromotionDto
>
createPromotion
(
Promotion
promotion
){
return
promotionRepository
.
save
(
promotion
).
map
(
PromotionDto:
:
generateDtoFromPromotion
);
}
}
src/test/java/com/nisum/ascend/promotions/controller/PromotionsControllerTest.java
View file @
057c3619
...
...
@@ -14,7 +14,6 @@ import org.springframework.test.annotation.DirtiesContext;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit.jupiter.SpringExtension
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
java.util.Arrays
;
...
...
@@ -52,6 +51,18 @@ class PromotionsControllerTest {
});
}
@Test
void
createPromotion
(){
Promotion
promotion
=
new
Promotion
(
"50OFF"
,
"SH1234"
,
(
float
)
0.5
,
5
);
webTestClient
.
post
().
uri
(
"/api/promos"
)
.
contentType
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
body
(
Mono
.
just
(
promotion
),
Promotion
.
class
)
.
exchange
()
.
expectStatus
().
isOk
()
.
expectBody
()
.
jsonPath
(
"$.promotionId"
,
"50OFF"
);
}
@Test
void
getPromotionsByProductSku
(){
String
skuWithOnePromo
=
"AFP-1"
;
...
...
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