Commit a412c8b8 authored by Kali Padhi's avatar Kali Padhi

kpadhi@nisum@.com :: EPE-001 :: PromotionEngine :: Added code for promo service

parent a7a24f9e
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
.gradle
*.iws
*.iml
*.ipr
build/
gradle/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
#Fri May 22 10:17:52 IST 2020
gradle.version=6.2.1
#Fri May 22 16:37:00 IST 2020
gradle.version=6.3
......@@ -14,6 +14,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
......
package com.nisum.epe.demo.model;
public class Promo {
private String id;
private String promoDesc;
public Promo(String id, String promoDesc) {
this.id = id;
this.promoDesc = promoDesc;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPromoDesc() {
return promoDesc;
}
public void setPromoDesc(String promoDesc) {
this.promoDesc = promoDesc;
}
}
package com.nisum.epe.demo.resources;
import com.nisum.epe.demo.model.Promo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@RestController
public class PromoEngineController {
@Autowired
PromoRepository promoRepository;
@GetMapping("/promo")
public Flux<List<Promo>> getPromo() {
return promoRepository.findAll();
}
@GetMapping("/promo/{promoId}")
public Flux<List<Promo>> getPromoById(@PathVariable("promoId") String promoId) {
final Flux<List<Promo>> listFlux = promoRepository.findAll();
return Flux.just(listFlux.blockFirst().
stream().
filter(promo -> promo.getId().equalsIgnoreCase(promoId)).
collect(Collectors.toList()));
}
}
@Component
class PromoRepository {
public Flux<List<Promo>> findAll(){
List<Promo> promos = Arrays.asList(new Promo("1", "BXGY"),
new Promo("2", "BXGX"),
new Promo("3", "%OFF"));
return Flux.just(promos);
}
}
server.port =9090
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment