added customers-query-side part
added service wrappers to customers-command-side and customers-query-side
This commit is contained in:
12
java-spring/customers-command-side-web/build.gradle
Normal file
12
java-spring/customers-command-side-web/build.gradle
Normal file
@@ -0,0 +1,12 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile project(":common-customers")
|
||||
compile project(":customers-command-side-backend")
|
||||
compile project(":common-web")
|
||||
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by popikyardo on 03.02.16.
|
||||
*/
|
||||
@Configuration
|
||||
@Import({CustomerConfiguration.class})
|
||||
@ComponentScan
|
||||
public class CommandSideWebCustomersConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
class FakeThing {}
|
||||
|
||||
@Bean
|
||||
public FakeThing init(RequestMappingHandlerAdapter adapter) {
|
||||
// https://jira.spring.io/browse/SPR-13083
|
||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
|
||||
handlers.add(0, new ObservableReturnValueHandler());
|
||||
adapter.setReturnValueHandlers(handlers);
|
||||
return new FakeThing();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerService;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* Created by popikyardo on 03.02.16.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/accounts")
|
||||
public class CustomerController {
|
||||
|
||||
private CustomerService customerService;
|
||||
|
||||
@Autowired
|
||||
public CustomerController(CustomerService customerService) {
|
||||
this.customerService = customerService;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public Observable<CustomerResponse> createAccount(@Validated @RequestBody CustomerInfo request) {
|
||||
return customerService.createCustomer(request)
|
||||
.map(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityIdentifier().getId(), request));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user