- updated swagger description
- changed customer registration endpoint - updated tests
This commit is contained in:
@@ -8,12 +8,16 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Cust
|
||||
*/
|
||||
public class CustomerCreatedEvent implements Event {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private CustomerInfo customerInfo;
|
||||
|
||||
public CustomerCreatedEvent() {
|
||||
}
|
||||
|
||||
public CustomerCreatedEvent(CustomerInfo customerInfo) {
|
||||
public CustomerCreatedEvent( String firstName, String lastName, CustomerInfo customerInfo) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.customerInfo = customerInfo;
|
||||
}
|
||||
|
||||
@@ -24,4 +28,20 @@ public class CustomerCreatedEvent implements Event {
|
||||
public void setCustomerInfo(CustomerInfo customerInfo) {
|
||||
this.customerInfo = customerInfo;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class AccountOpenEventSerializationTest {
|
||||
|
||||
@Test
|
||||
public void shouldSerde() {
|
||||
AccountOpenedEvent event = new AccountOpenedEvent(new BigDecimal(55));
|
||||
AccountOpenedEvent event = new AccountOpenedEvent("00000000-00000000", "My Account", new BigDecimal(55));
|
||||
String json = JSonMapper.toJson(event, EventStoreCommonObjectMapping.getObjectMapper());
|
||||
System.out.println("json=" + json);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
|
||||
@@ -3,15 +3,20 @@ package net.chrisrichardson.eventstore.javaexamples.banking.common.customers;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Created by popikyardo on 02.02.16.
|
||||
*/
|
||||
public class Address {
|
||||
|
||||
@NotNull
|
||||
private String street1;
|
||||
private String street2;
|
||||
@NotNull
|
||||
private String city;
|
||||
@NotNull
|
||||
private String state;
|
||||
@NotNull
|
||||
private String zipCode;
|
||||
|
||||
public Address() {
|
||||
|
||||
@@ -3,12 +3,17 @@ package net.chrisrichardson.eventstore.javaexamples.banking.common.customers;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Created by popikyardo on 03.02.16.
|
||||
*/
|
||||
public class CustomerInfo {
|
||||
@NotNull
|
||||
protected String email;
|
||||
@NotNull
|
||||
protected String ssn;
|
||||
@NotNull
|
||||
protected String phoneNumber;
|
||||
protected Address address;
|
||||
|
||||
|
||||
@@ -6,14 +6,25 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Cust
|
||||
* Created by popikyardo on 02.02.16.
|
||||
*/
|
||||
public class CreateCustomerCommand implements CustomerCommand {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private CustomerInfo customerInfo;
|
||||
|
||||
public CreateCustomerCommand(CustomerInfo customerInfo) {
|
||||
public CreateCustomerCommand(String firstName, String lastName, CustomerInfo customerInfo) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.customerInfo = customerInfo;
|
||||
}
|
||||
|
||||
public CustomerInfo getCustomerInfo() {
|
||||
return customerInfo;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class Customer extends ReflectiveMutableCommandProcessingAggregate<Custom
|
||||
|
||||
|
||||
public List<Event> process(CreateCustomerCommand cmd) {
|
||||
return EventUtil.events(new CustomerCreatedEvent(cmd.getCustomerInfo()));
|
||||
return EventUtil.events(new CustomerCreatedEvent(cmd.getFirstName(), cmd.getLastName(), cmd.getCustomerInfo()));
|
||||
}
|
||||
|
||||
public void apply(CustomerCreatedEvent event) {
|
||||
|
||||
@@ -14,8 +14,8 @@ public class CustomerService {
|
||||
this.accountRepository = accountRepository;
|
||||
}
|
||||
|
||||
public rx.Observable<EntityWithIdAndVersion<Customer>> createCustomer(CustomerInfo customerInfo) {
|
||||
return accountRepository.save(new CreateCustomerCommand(customerInfo));
|
||||
public rx.Observable<EntityWithIdAndVersion<Customer>> createCustomer(String firstName, String lastName, CustomerInfo customerInfo) {
|
||||
return accountRepository.save(new CreateCustomerCommand(firstName, lastName, customerInfo));
|
||||
}
|
||||
|
||||
public rx.Observable<EntityWithIdAndVersion<Customer>> addToAccount(String customerId, String accountId, String title, String owner) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.
|
||||
import net.chrisrichardson.eventstore.CommandProcessingAggregates;
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerCreatedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
import org.junit.Assert;
|
||||
@@ -19,10 +20,10 @@ public class CustomerTest {
|
||||
|
||||
CustomerInfo customerInfo = generateCustomerInfo();
|
||||
|
||||
List<Event> events = CommandProcessingAggregates.processToList(customer, new CreateCustomerCommand(customerInfo));
|
||||
List<Event> events = CommandProcessingAggregates.processToList(customer, new CreateCustomerCommand("John", "Doe", customerInfo));
|
||||
|
||||
Assert.assertEquals(1, events.size());
|
||||
Assert.assertEquals(AccountOpenedEvent.class, events.get(0).getClass());
|
||||
Assert.assertEquals(CustomerCreatedEvent.class, events.get(0).getClass());
|
||||
|
||||
customer.applyEvent(events.get(0));
|
||||
Assert.assertEquals(customerInfo, customer.getCustomerInfo());
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers.CreateCustomerRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -35,7 +36,7 @@ public class CustomersCommandSideServiceIntegrationTest {
|
||||
public void shouldCreateCustomer() {
|
||||
CustomerInfo customerInfo = generateCustomerInfo();
|
||||
|
||||
final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"),customerInfo, CustomerResponse.class).getBody();
|
||||
final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"),new CreateCustomerRequest("John", "Doe", customerInfo), CustomerResponse.class).getBody();
|
||||
final String customerId = customerResponse.getId();
|
||||
|
||||
Assert.assertNotNull(customerId);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Created by Main on 09.02.2016.
|
||||
*/
|
||||
public class CreateCustomerRequest {
|
||||
@NotNull
|
||||
private String firstName;
|
||||
@NotNull
|
||||
private String lastName;
|
||||
private CustomerInfo customerInfo;
|
||||
|
||||
public CreateCustomerRequest() {
|
||||
}
|
||||
|
||||
public CreateCustomerRequest(String firstName, String lastName, CustomerInfo customerInfo) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.customerInfo = customerInfo;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public CustomerInfo getCustomerInfo() {
|
||||
return customerInfo;
|
||||
}
|
||||
|
||||
public void setCustomerInfo(CustomerInfo customerInfo) {
|
||||
this.customerInfo = customerInfo;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
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.http.ResponseEntity;
|
||||
@@ -24,9 +23,9 @@ public class CustomerController {
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public Observable<CustomerResponse> createCustomer(@Validated @RequestBody CustomerInfo request) {
|
||||
return customerService.createCustomer(request)
|
||||
.map(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityIdentifier().getId(), request));
|
||||
public Observable<CustomerResponse> createCustomer(@Validated @RequestBody CreateCustomerRequest request) {
|
||||
return customerService.createCustomer(request.getFirstName(), request.getLastName(), request.getCustomerInfo())
|
||||
.map(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityIdentifier().getId(), request.getCustomerInfo()));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}/toaccounts", method = RequestMethod.POST)
|
||||
|
||||
@@ -26,11 +26,11 @@ public class CustomerInfoUpdateService {
|
||||
this.mongoTemplate = mongoTemplate;
|
||||
}
|
||||
|
||||
public void create(String id, CustomerInfo customerInfo) {
|
||||
public void create(String id, String firstName, String lastName, CustomerInfo customerInfo) {
|
||||
try {
|
||||
accountInfoRepository.save(new QuerySideCustomer(id,
|
||||
"",
|
||||
"",
|
||||
firstName,
|
||||
lastName,
|
||||
customerInfo.getEmail(),
|
||||
customerInfo.getSsn(),
|
||||
customerInfo.getPhoneNumber(),
|
||||
|
||||
@@ -30,7 +30,7 @@ public class CustomerQueryWorkflow implements CompoundEventHandler {
|
||||
CustomerCreatedEvent event = de.event();
|
||||
String id = de.getEntityIdentifier().getId();
|
||||
|
||||
customerInfoUpdateService.create(id, event.getCustomerInfo());
|
||||
customerInfoUpdateService.create(id, event.getFirstName(), event.getLastName(), event.getCustomerInfo());
|
||||
return Observable.just(null);
|
||||
}
|
||||
@EventHandlerMethod
|
||||
|
||||
@@ -19,8 +19,8 @@ public class QuerySideCustomerConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomerInfoUpdateService customerInfoUpdateService(QuerySideCustomerRepository querySideCustomerRepository) {
|
||||
return new CustomerInfoUpdateService(querySideCustomerRepository);
|
||||
public CustomerInfoUpdateService customerInfoUpdateService(QuerySideCustomerRepository querySideCustomerRepository, MongoTemplate mongoTemplate) {
|
||||
return new CustomerInfoUpdateService(querySideCustomerRepository, mongoTemplate);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.QuerySideCustomerConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
||||
@@ -12,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
@Configuration
|
||||
@Import({CustomersQuerySideServiceConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@Import({QuerySideCustomerConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class CustomersQuerySideServiceConfiguration {
|
||||
|
||||
@@ -63,10 +63,10 @@ public class EndToEndTest {
|
||||
BigDecimal finalFromAccountBalance = initialFromAccountBalance.subtract(amountToTransfer);
|
||||
BigDecimal finalToAccountBalance = initialToAccountBalance.add(amountToTransfer);
|
||||
|
||||
final CreateAccountResponse fromAccount = restTemplate.postForEntity(accountsCommandSideBaseUrl("/accounts"), new CreateAccountRequest(initialFromAccountBalance), CreateAccountResponse.class).getBody();
|
||||
final CreateAccountResponse fromAccount = restTemplate.postForEntity(accountsCommandSideBaseUrl("/accounts"), new CreateAccountRequest("00000000-00000000", "My Account", initialFromAccountBalance), CreateAccountResponse.class).getBody();
|
||||
final String fromAccountId = fromAccount.getAccountId();
|
||||
|
||||
CreateAccountResponse toAccount = restTemplate.postForEntity(accountsCommandSideBaseUrl("/accounts"), new CreateAccountRequest(initialToAccountBalance), CreateAccountResponse.class).getBody();
|
||||
CreateAccountResponse toAccount = restTemplate.postForEntity(accountsCommandSideBaseUrl("/accounts"), new CreateAccountRequest("00000000-00000000", "My Account", initialToAccountBalance), CreateAccountResponse.class).getBody();
|
||||
String toAccountId = toAccount.getAccountId();
|
||||
|
||||
Assert.assertNotNull(fromAccountId);
|
||||
|
||||
@@ -50,10 +50,10 @@ public class BankingWebIntegrationTest {
|
||||
BigDecimal finalFromAccountBalance = initialFromAccountBalance.subtract(amountToTransfer);
|
||||
BigDecimal finalToAccountBalance = initialToAccountBalance.add(amountToTransfer);
|
||||
|
||||
final CreateAccountResponse fromAccount = restTemplate.postForEntity(baseUrl("/accounts"), new CreateAccountRequest(initialFromAccountBalance), CreateAccountResponse.class).getBody();
|
||||
final CreateAccountResponse fromAccount = restTemplate.postForEntity(baseUrl("/accounts"), new CreateAccountRequest("00000000-00000000", "My Account", initialFromAccountBalance), CreateAccountResponse.class).getBody();
|
||||
final String fromAccountId = fromAccount.getAccountId();
|
||||
|
||||
CreateAccountResponse toAccount = restTemplate.postForEntity(baseUrl("/accounts"), new CreateAccountRequest(initialToAccountBalance), CreateAccountResponse.class).getBody();
|
||||
CreateAccountResponse toAccount = restTemplate.postForEntity(baseUrl("/accounts"), new CreateAccountRequest("00000000-00000000", "My Account", initialToAccountBalance), CreateAccountResponse.class).getBody();
|
||||
String toAccountId = toAccount.getAccountId();
|
||||
|
||||
Assert.assertNotNull(fromAccountId);
|
||||
|
||||
@@ -34,80 +34,6 @@
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/register/step_1": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"auth-controller"
|
||||
],
|
||||
"summary": "doRegisterStep1",
|
||||
"operationId": "doRegisterStep1UsingPOST",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"*/*"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "request",
|
||||
"description": "request",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/RegisterStep1Request"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/CustomerResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Validation error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/register/step_2": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"auth-controller"
|
||||
],
|
||||
"summary": "doRegisterStep1",
|
||||
"operationId": "doRegisterStep1UsingPOST",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"*/*"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "request",
|
||||
"description": "request",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/RegisterStep2Request"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/CustomerResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Validation error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/login": {
|
||||
"post": {
|
||||
"tags": [
|
||||
@@ -224,7 +150,7 @@
|
||||
"description": "customer",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/CustomerInfo"
|
||||
"$ref": "#/definitions/CreateCustomerRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -389,8 +315,8 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"RegisterStep1Request": {
|
||||
"required": [ "email" ],
|
||||
"CreateCustomerRequest": {
|
||||
"required": [ "email", "ssn", "phoneNumber" ],
|
||||
"properties": {
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
@@ -400,12 +326,7 @@
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"RegisterStep2Request": {
|
||||
"required": [ "ssn", "phoneNumber" ],
|
||||
"properties": {
|
||||
},
|
||||
"ssn": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -432,6 +353,7 @@
|
||||
}
|
||||
},
|
||||
"Address": {
|
||||
"required": [ "street1", "city", "state", "zipCode" ],
|
||||
"properties": {
|
||||
"street1": {
|
||||
"type": "string"
|
||||
|
||||
Reference in New Issue
Block a user