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
cd29ffe2
Commit
cd29ffe2
authored
May 05, 2021
by
John Lam
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'AFP-64' into dev
parents
8034f326
cf3f015f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
147 additions
and
4 deletions
+147
-4
.gitignore
.gitignore
+1
-0
pom.xml
pom.xml
+5
-1
PromotionsController.java
...um/ascend/promotions/controller/PromotionsController.java
+46
-2
PromotionDto.java
...in/java/com/nisum/ascend/promotions/dto/PromotionDto.java
+21
-0
Promotion.java
...ain/java/com/nisum/ascend/promotions/model/Promotion.java
+1
-1
PromotionRepository.java
...sum/ascend/promotions/repository/PromotionRepository.java
+2
-0
PromotionService.java
...com/nisum/ascend/promotions/service/PromotionService.java
+10
-0
application-test.properties
src/main/resources/application-test.properties
+5
-0
application.properties
src/main/resources/application.properties
+5
-0
PromotionsControllerTest.java
...scend/promotions/controller/PromotionsControllerTest.java
+51
-0
No files found.
.gitignore
View file @
cd29ffe2
...
...
@@ -31,3 +31,4 @@ build/
### VS Code ###
.vscode/
/src/main/resources/secret.properties
pom.xml
View file @
cd29ffe2
...
...
@@ -29,7 +29,11 @@
<groupId>
org.springframework.kafka
</groupId>
<artifactId>
spring-kafka
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-boot-starter
</artifactId>
<version>
3.0.0
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
...
...
src/main/java/com/nisum/ascend/promotions/controller/PromotionsController.java
View file @
cd29ffe2
package
com
.
nisum
.
ascend
.
promotions
.
controller
;
import
com.nisum.ascend.promotions.dto.PromotionDto
;
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.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
java.util.ArrayList
;
@RestController
@RequestMapping
(
"/api/promos"
)
...
...
@@ -12,4 +18,42 @@ public class PromotionsController {
@Autowired
PromotionService
promotionService
;
@GetMapping
()
public
ResponseEntity
<
Flux
<
PromotionDto
>>
getAllPromotions
(
@RequestParam
(
required
=
false
)
String
sku
){
if
(
sku
!=
null
){
return
ResponseEntity
.
ok
(
promotionService
.
findPromotionsByProductSku
(
sku
));
}
else
return
ResponseEntity
.
ok
(
promotionService
.
findAll
());
}
@GetMapping
(
"/{id}"
)
public
Mono
<
ResponseEntity
<
PromotionDto
>>
getPromotionById
(
@PathVariable
String
id
){
//TODO: get promo by ID
return
null
;
}
@PostMapping
()
public
Mono
<
ResponseEntity
<
PromotionDto
>>
createPromotion
(
@RequestBody
Promotion
newPromotion
){
//TODO: create promotion
return
null
;
}
@PostMapping
(
"/bulkSearch"
)
public
Flux
<
ResponseEntity
<
PromotionDto
>>
bulkSearchPromotionsByItemSku
(){
//TODO: bulk search by list of item SKUs
return
null
;
}
@PutMapping
(
"/{promoId}"
)
public
Mono
<
ResponseEntity
<
PromotionDto
>>
updatePromotionById
(
@PathVariable
String
promoId
,
@RequestBody
Promotion
newPromotion
){
//TODO: update promotion
return
null
;
}
@DeleteMapping
(
"/{promoId}"
)
public
Mono
<
ResponseEntity
<
PromotionDto
>>
deletePromotionById
(
@PathVariable
String
promoId
){
//TODO: delete promotion
return
null
;
}
}
src/main/java/com/nisum/ascend/promotions/dto/PromotionDto.java
0 → 100644
View file @
cd29ffe2
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/model/Promotion.java
View file @
cd29ffe2
...
...
@@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Getter
@Setter
@Document
@Document
(
collection
=
"promotions"
)
public
class
Promotion
{
@Id
private
String
id
;
...
...
src/main/java/com/nisum/ascend/promotions/repository/PromotionRepository.java
View file @
cd29ffe2
...
...
@@ -4,7 +4,9 @@ package com.nisum.ascend.promotions.repository;
import
com.nisum.ascend.promotions.model.Promotion
;
import
org.springframework.data.mongodb.repository.ReactiveMongoRepository
;
import
org.springframework.stereotype.Repository
;
import
reactor.core.publisher.Flux
;
@Repository
public
interface
PromotionRepository
extends
ReactiveMongoRepository
<
Promotion
,
String
>
{
Flux
<
Promotion
>
findByProductSku
(
String
sku
);
}
src/main/java/com/nisum/ascend/promotions/service/PromotionService.java
View file @
cd29ffe2
package
com
.
nisum
.
ascend
.
promotions
.
service
;
import
com.nisum.ascend.promotions.dto.PromotionDto
;
import
com.nisum.ascend.promotions.repository.PromotionRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
reactor.core.publisher.Flux
;
@Service
public
class
PromotionService
{
@Autowired
PromotionRepository
promotionRepository
;
public
Flux
<
PromotionDto
>
findAll
(){
return
promotionRepository
.
findAll
().
map
(
PromotionDto:
:
generateDtoFromPromotion
);
}
public
Flux
<
PromotionDto
>
findPromotionsByProductSku
(
String
sku
){
return
promotionRepository
.
findByProductSku
(
sku
).
map
(
PromotionDto:
:
generateDtoFromPromotion
);
}
}
src/main/resources/application-test.properties
0 → 100644
View file @
cd29ffe2
spring.config.import
=
classpath:secret.properties
spring.data.mongodb.uri
=
mongodb+srv://admin:${db.password}@inventory-promotions.d4nfz.mongodb
\
.net/${spring.data.mongodb.database}?retryWrites=true&w=majority
spring.data.mongodb.database
=
test
\ No newline at end of file
src/main/resources/application.properties
View file @
cd29ffe2
spring.config.import
=
classpath:secret.properties
server.port
=
8081
spring.data.mongodb.uri
=
mongodb+srv://admin:${db.password}@inventory-promotions.d4nfz.mongodb
\
.net/${spring.data.mongodb.database}?retryWrites=true&w=majority
spring.data.mongodb.database
=
products-promotions-DB
\ No newline at end of file
src/test/java/com/nisum/ascend/promotions/controller/PromotionsControllerTest.java
0 → 100644
View file @
cd29ffe2
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
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.MediaType
;
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
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
@ExtendWith
(
SpringExtension
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
@DirtiesContext
@AutoConfigureWebTestClient
@ActiveProfiles
(
"test"
)
@Slf4j
class
PromotionsControllerTest
{
@Autowired
private
WebTestClient
webTestClient
;
@BeforeEach
void
setUp
()
{
}
@Test
void
getAllPromotions
()
{
webTestClient
.
get
().
uri
(
"http://localhost:8081/api/promos"
).
exchange
()
.
expectStatus
().
isOk
()
.
expectHeader
().
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
expectBodyList
(
PromotionDto
.
class
)
.
hasSize
(
2
)
.
consumeWith
(
promo
->{
List
<
PromotionDto
>
promos
=
promo
.
getResponseBody
();
assert
promos
!=
null
;
promos
.
forEach
(
p
->{
assertNotNull
(
p
.
getPromotionId
());
assertNotNull
(
p
.
getProductSku
());
System
.
out
.
println
(
p
.
getPromotionId
());
});
});
}
}
\ 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