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
08e090cd
Commit
08e090cd
authored
May 10, 2021
by
Sumaiyya Burney
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'AFP-63' into 'dev'
Afp 63 See merge request
!10
parents
4b7f1cf5
48d05f8a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
3 deletions
+60
-3
PromotionsController.java
...um/ascend/promotions/controller/PromotionsController.java
+6
-3
ResourceNotFoundException.java
...scend/promotions/exception/ResourceNotFoundException.java
+15
-0
PromotionService.java
...com/nisum/ascend/promotions/service/PromotionService.java
+10
-0
PromotionsControllerTest.java
...scend/promotions/controller/PromotionsControllerTest.java
+29
-0
No files found.
src/main/java/com/nisum/ascend/promotions/controller/PromotionsController.java
View file @
08e090cd
...
...
@@ -57,8 +57,11 @@ public class PromotionsController {
@DeleteMapping
(
"/{promoId}"
)
public
Mono
<
ResponseEntity
<
PromotionDto
>>
deletePromotionById
(
@PathVariable
String
promoId
){
//TODO: delete promotion
return
null
;
public
Mono
<
ResponseEntity
<
Void
>>
deletePromotionById
(
@PathVariable
(
"promoId"
)
String
promoId
){
return
promotionService
.
deletePromotion
(
promoId
)
.
map
(
res
->
ResponseEntity
.
ok
().<
Void
>
build
())
.
defaultIfEmpty
(
ResponseEntity
.
notFound
().
build
());
}
}
src/main/java/com/nisum/ascend/promotions/exception/ResourceNotFoundException.java
0 → 100644
View file @
08e090cd
package
com
.
nisum
.
ascend
.
promotions
.
exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
@ResponseStatus
(
value
=
HttpStatus
.
NOT_FOUND
)
public
class
ResourceNotFoundException
extends
Exception
{
HttpStatus
status
;
public
ResourceNotFoundException
(
HttpStatus
status
,
String
message
)
{
super
(
message
);
this
.
status
=
status
;
}
}
src/main/java/com/nisum/ascend/promotions/service/PromotionService.java
View file @
08e090cd
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
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
reactor.core.publisher.Flux
;
import
java.util.List
;
...
...
@@ -45,4 +47,12 @@ public class PromotionService {
});
}
public
Mono
<
Promotion
>
deletePromotion
(
String
promoId
){
return
promotionRepository
.
findByPromotionId
(
promoId
)
.
flatMap
(
promo
->
promotionRepository
.
delete
(
promo
)
.
then
(
Mono
.
just
(
promo
)))
.
switchIfEmpty
(
Mono
.
error
(
new
ResourceNotFoundException
(
HttpStatus
.
NOT_FOUND
,
"Promo Not Found"
)));
}
}
src/test/java/com/nisum/ascend/promotions/controller/PromotionsControllerTest.java
View file @
08e090cd
...
...
@@ -128,6 +128,35 @@ class PromotionsControllerTest {
.
jsonPath
(
"$.minimumQuantity"
).
isEqualTo
(
1
);
}
@Test
void
deletePromotion
(){
Promotion
promo
=
new
Promotion
(
"deleteTest"
,
"AFP-1"
,
0.33f
,
3
);
webTestClient
.
get
()
.
uri
(
"/api/promos"
.
concat
(
"/{promoId}"
),
promo
.
getPromotionId
())
.
exchange
()
.
expectStatus
().
isNotFound
();
webTestClient
.
post
()
.
uri
(
"/api/promos"
)
.
contentType
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
body
(
Mono
.
just
(
promo
),
Promotion
.
class
)
.
exchange
()
.
expectStatus
().
isOk
()
.
expectBody
(
Promotion
.
class
);
webTestClient
.
delete
()
.
uri
(
"/api/promos"
.
concat
(
"/{promoId}"
),
promo
.
getPromotionId
())
.
accept
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
exchange
()
.
expectStatus
().
isOk
()
.
expectBody
(
Void
.
class
);
webTestClient
.
get
()
.
uri
(
"/api/promos"
.
concat
(
"/{promoId}"
),
promo
.
getPromotionId
())
.
exchange
()
.
expectStatus
().
isNotFound
();
}
@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