Last active
June 14, 2021 01:19
-
-
Save apc-kamezaki/d0f8d80eeb2a057535e1d12e82fc8f38 to your computer and use it in GitHub Desktop.
pgdemo-bff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
@Slf4j | |
@RequiredArgsConstructor | |
public class DemoService { | |
private final BackendConfig backendConfig; | |
private final @Qualifier("backendWebClient") WebClient demoClient; | |
public Mono<Object> greeting() { | |
log.info("get greeting"); | |
return demoClient.get().uri(String.format("%s/%s", backendConfig.getDemoBasePath(), "greetings")) | |
.accept(MediaType.APPLICATION_JSON) | |
.retrieve() | |
.bodyToMono(Object.class); | |
} | |
public Mono<Object> tasks() { | |
log.info("get tasks"); | |
return demoClient.get().uri(String.format("%s/%s", backendConfig.getDemoBasePath(), "tasks")) | |
.accept(MediaType.APPLICATION_JSON) | |
.retrieve() | |
.bodyToMono(Object.class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequiredArgsConstructor | |
@RequestMapping("/greeting-tasks") | |
public class GreetingTaskController { | |
private final DemoService demoService; | |
@RequestMapping() | |
public Mono<GreetingTask> get() { | |
return Mono.zip(demoService.greeting(), demoService.tasks()) | |
.map(tuple -> { | |
final var greeting = tuple.getT1(); | |
final var tasks = tuple.getT2(); | |
return GreetingTask.builder().greeting(greeting).tasks(tasks).build(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment