- updated swagger description

- added /customers/{id}/toaccounts endpoint
This commit is contained in:
Main
2016-02-08 22:54:03 +03:00
parent 59ecaa804a
commit cd35ac3d31
34 changed files with 487 additions and 76 deletions

View File

@@ -16,7 +16,7 @@ public class Account extends ReflectiveMutableCommandProcessingAggregate<Account
private BigDecimal balance;
public List<Event> process(OpenAccountCommand cmd) {
return EventUtil.events(new AccountOpenedEvent(cmd.getCustomerId(), cmd.getInitialBalance()));
return EventUtil.events(new AccountOpenedEvent(cmd.getCustomerId(), cmd.getTitle(), cmd.getInitialBalance()));
}
public List<Event> process(DebitAccountCommand cmd) {

View File

@@ -14,8 +14,8 @@ public class AccountService {
this.accountRepository = accountRepository;
}
public rx.Observable<EntityWithIdAndVersion<Account>> openAccount(String customerId, BigDecimal initialBalance) {
return accountRepository.save(new OpenAccountCommand(customerId, initialBalance));
public rx.Observable<EntityWithIdAndVersion<Account>> openAccount(String customerId, String title, BigDecimal initialBalance) {
return accountRepository.save(new OpenAccountCommand(customerId, title, initialBalance));
}
}

View File

@@ -6,9 +6,12 @@ import java.math.BigDecimal;
public class OpenAccountCommand implements AccountCommand {
private String customerId;
private String title;
private BigDecimal initialBalance;
public OpenAccountCommand(String customerId, BigDecimal initialBalance) {
public OpenAccountCommand(String customerId, String title, BigDecimal initialBalance) {
this.customerId = customerId;
this.title = title;
this.initialBalance = initialBalance;
}
@@ -19,4 +22,8 @@ public class OpenAccountCommand implements AccountCommand {
public String getCustomerId() {
return customerId;
}
public String getTitle() {
return title;
}
}

View File

@@ -14,9 +14,10 @@ public class AccountTest {
@Test
public void testSomething() {
Account account = new Account();
String title = "My Account";
String customerId = "00000000-00000000";
BigDecimal initialBalance = new BigDecimal(512);
List<Event> events = CommandProcessingAggregates.processToList(account, (AccountCommand)new OpenAccountCommand(customerId, initialBalance));
List<Event> events = CommandProcessingAggregates.processToList(account, (AccountCommand)new OpenAccountCommand(customerId, title, initialBalance));
Assert.assertEquals(1, events.size());
Assert.assertEquals(AccountOpenedEvent.class, events.get(0).getClass());

View File

@@ -38,11 +38,12 @@ public class AccountsCommandSideServiceIntegrationTest {
BigDecimal initialToAccountBalance = new BigDecimal(100);
BigDecimal amountToTransfer = new BigDecimal(150);
String customerId = "00000000-00000000";
String title = "My Account";
final CreateAccountResponse fromAccount = restTemplate.postForEntity(baseUrl("/accounts"), new CreateAccountRequest(customerId, initialFromAccountBalance), CreateAccountResponse.class).getBody();
final CreateAccountResponse fromAccount = restTemplate.postForEntity(baseUrl("/accounts"), new CreateAccountRequest(customerId, title, initialFromAccountBalance), CreateAccountResponse.class).getBody();
final String fromAccountId = fromAccount.getAccountId();
CreateAccountResponse toAccount = restTemplate.postForEntity(baseUrl("/accounts"), new CreateAccountRequest(customerId, initialToAccountBalance), CreateAccountResponse.class).getBody();
CreateAccountResponse toAccount = restTemplate.postForEntity(baseUrl("/accounts"), new CreateAccountRequest(customerId, title, initialToAccountBalance), CreateAccountResponse.class).getBody();
String toAccountId = toAccount.getAccountId();
Assert.assertNotNull(fromAccountId);

View File

@@ -22,7 +22,7 @@ public class AccountController {
@RequestMapping(method = RequestMethod.POST)
public Observable<CreateAccountResponse> createAccount(@Validated @RequestBody CreateAccountRequest request) {
return accountService.openAccount(request.getCustomerId(), request.getInitialBalance())
return accountService.openAccount(request.getCustomerId(), request.getTitle(), request.getInitialBalance())
.map(entityAndEventInfo -> new CreateAccountResponse(entityAndEventInfo.getEntityIdentifier().getId()));
}
}

View File

@@ -10,6 +10,8 @@ public class CreateAccountRequest {
@NotNull
private String customerId;
private String title;
@NotNull
@DecimalMin("0")
private BigDecimal initialBalance;
@@ -17,8 +19,9 @@ public class CreateAccountRequest {
public CreateAccountRequest() {
}
public CreateAccountRequest(String customerId, BigDecimal initialBalance) {
public CreateAccountRequest(String customerId, String title, BigDecimal initialBalance) {
this.customerId = customerId;
this.title = title;
this.initialBalance = initialBalance;
}
@@ -37,4 +40,12 @@ public class CreateAccountRequest {
public void setInitialBalance(BigDecimal initialBalance) {
this.initialBalance = initialBalance;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

View File

@@ -9,6 +9,7 @@ public class AccountInfo {
private String id;
private String customerId;
private String title;
private long balance;
private List<AccountChangeInfo> changes;
private List<AccountTransactionInfo> transactions;
@@ -17,10 +18,11 @@ public class AccountInfo {
private AccountInfo() {
}
public AccountInfo(String id, String customerId, long balance, List<AccountChangeInfo> changes, List<AccountTransactionInfo> transactions, String version) {
public AccountInfo(String id, String customerId, String title, long balance, List<AccountChangeInfo> changes, List<AccountTransactionInfo> transactions, String version) {
this.id = id;
this.customerId = customerId;
this.title = title;
this.balance = balance;
this.changes = changes;
this.transactions = transactions;
@@ -35,6 +37,10 @@ public class AccountInfo {
return customerId;
}
public String getTitle() {
return title;
}
public long getBalance() {
return balance;
}

View File

@@ -26,11 +26,12 @@ public class AccountInfoUpdateService {
public void create(String accountId, String customerId, BigDecimal initialBalance, String version) {
public void create(String accountId, String customerId, String title, BigDecimal initialBalance, String version) {
try {
accountInfoRepository.save(new AccountInfo(
accountId,
customerId,
title,
toIntegerRepr(initialBalance),
Collections.<AccountChangeInfo>emptyList(),
Collections.<AccountTransactionInfo>emptyList(),

View File

@@ -38,7 +38,8 @@ public class AccountQueryWorkflow implements CompoundEventHandler {
logger.info("**************** account version=" + id + ", " + eventId);
BigDecimal initialBalance = event.getInitialBalance();
String customerId = event.getCustomerId();
accountInfoUpdateService.create(id, customerId, initialBalance, eventId);
String title = event.getTitle();
accountInfoUpdateService.create(id, customerId, title, initialBalance, eventId);
return Observable.just(null);
}

View File

@@ -43,9 +43,9 @@ public class MoneyTransferIntegrationTest {
@Test
public void shouldTransferMoney() {
final EntityWithIdAndVersion<Account> fromAccount= await(accountService.openAccount("00000000-00000000", new BigDecimal(150)));
final EntityWithIdAndVersion<Account> fromAccount= await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150)));
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", new BigDecimal(300)));
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
@@ -98,9 +98,9 @@ public class MoneyTransferIntegrationTest {
@Test
public void shouldFailDueToInsufficientFunds() {
final EntityWithIdAndVersion<Account> fromAccount= await(accountService.openAccount("00000000-00000000", new BigDecimal(150)));
final EntityWithIdAndVersion<Account> fromAccount= await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150)));
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", new BigDecimal(300)));
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),

View File

@@ -45,9 +45,9 @@ public class AccountQuerySideIntegrationTest {
@Test
public void shouldUpdateQuerySide() throws Exception {
final EntityWithIdAndVersion<Account> fromAccount = await(accountService.openAccount("00000000-00000000", new BigDecimal(150)));
final EntityWithIdAndVersion<Account> fromAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150)));
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", new BigDecimal(300)));
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),

View File

@@ -0,0 +1,13 @@
apply plugin: 'java'
dependencies {
compile project(":common-auth")
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
compile "org.springframework.security:spring-security-config:4.0.2.RELEASE"
compile "org.springframework.security:spring-security-web:4.0.2.RELEASE"
testCompile "junit:junit:4.11"
}

View File

@@ -0,0 +1,45 @@
package net.chrisrichardson.eventstore.javaexamples.banking.commonauth.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.AuthRequest;
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.AuthResponse;
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.token.Token;
import org.springframework.security.core.token.TokenService;
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.RestController;
import javax.validation.Valid;
import java.io.IOException;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
/**
* Created by popikyardo on 21.09.15.
*/
@RestController
@Validated
public class AuthController {
@Autowired
private TokenService tokenService;
private static ObjectMapper objectMapper = new ObjectMapper();
@RequestMapping(value = "/login", method = POST)
public ResponseEntity<AuthResponse> doAuth(@RequestBody @Valid AuthRequest request) throws IOException {
User user = new User();
user.setEmail(request.getEmail());
Token token = tokenService.allocateToken(objectMapper.writeValueAsString(user));
return ResponseEntity.status(HttpStatus.OK)
.body(new AuthResponse(token.getKey()));
}
}

View File

@@ -0,0 +1,29 @@
package net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
/**
* Created by popikyardo on 19.10.15.
*/
public class AuthRequest {
@NotBlank
@Email
private String email;
public AuthRequest() {
}
public AuthRequest(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

View File

@@ -0,0 +1,23 @@
package net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model;
/**
* Created by popikyardo on 21.09.15.
*/
public class AuthResponse {
private String token;
public AuthResponse() {
}
public AuthResponse(String token) {
this.token = token;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}

View File

@@ -55,7 +55,9 @@ public class AuthConfiguration extends WebSecurityConfigurerAdapter {
.antMatchers("/js/**").permitAll()
.antMatchers("/styles/**").permitAll()
.antMatchers("/views/**").permitAll()
.antMatchers(HttpMethod.POST, "/authenticate").permitAll()
.antMatchers(HttpMethod.POST, "/register/step_1").permitAll()
.antMatchers(HttpMethod.POST, "/register/step_2").permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.anyRequest().authenticated().and()
.addFilterBefore(new StatelessAuthenticationFilter(tokenAuthenticationService), UsernamePasswordAuthenticationFilter.class);
}

View File

@@ -8,13 +8,15 @@ import java.math.BigDecimal;
public class AccountOpenedEvent implements Event {
private String customerId;
private String title;
private BigDecimal initialBalance;
private AccountOpenedEvent() {
}
public AccountOpenedEvent(String customerId, BigDecimal initialBalance) {
public AccountOpenedEvent(String customerId, String title, BigDecimal initialBalance) {
this.customerId = customerId;
this.title = title;
this.initialBalance = initialBalance;
}
@@ -22,6 +24,10 @@ public class AccountOpenedEvent implements Event {
return customerId;
}
public String getTitle() {
return title;
}
public BigDecimal getInitialBalance() {
return initialBalance;
}

View File

@@ -0,0 +1,46 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers;
import net.chrisrichardson.eventstore.Event;
/**
* Created by Main on 08.02.2016.
*/
public class CustomerAddedToAccount implements Event {
private String accountId;
private String accountOwner;
private String title;
public CustomerAddedToAccount() {
}
public CustomerAddedToAccount(String accountId, String accountOwner, String title) {
this.accountId = accountId;
this.accountOwner = accountOwner;
this.title = title;
}
public String getAccountId() {
return accountId;
}
public void setAccountId(String accountId) {
this.accountId = accountId;
}
public String getAccountOwner() {
return accountOwner;
}
public void setAccountOwner(String accountOwner) {
this.accountOwner = accountOwner;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

View File

@@ -0,0 +1,29 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers;
/**
* Created by Main on 08.02.2016.
*/
public class AddToAccountCommand implements CustomerCommand {
private String accountId;
private String accountOwner;
private String title;
public AddToAccountCommand(String accountId, String accountOwner, String title) {
this.accountId = accountId;
this.accountOwner = accountOwner;
this.title = title;
}
public String getAccountId() {
return accountId;
}
public String getAccountOwner() {
return accountOwner;
}
public String getTitle() {
return title;
}
}

View File

@@ -1,6 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
import net.chrisrichardson.eventstore.repository.AggregateRepository;
@@ -17,4 +18,8 @@ public class CustomerService {
return accountRepository.save(new CreateCustomerCommand(customerInfo));
}
public rx.Observable<EntityWithIdAndVersion<Customer>> addToAccount(String customerId, String accountId, String title, String owner) {
return accountRepository.update(new EntityIdentifier(customerId), new AddToAccountCommand(accountId, title, owner));
}
}

View File

@@ -4,18 +4,16 @@ import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.c
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;
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 org.springframework.web.bind.annotation.*;
import rx.Observable;
/**
* Created by popikyardo on 03.02.16.
*/
@RestController
@RequestMapping("/accounts")
@RequestMapping("/customer")
public class CustomerController {
private CustomerService customerService;
@@ -26,8 +24,15 @@ public class CustomerController {
}
@RequestMapping(method = RequestMethod.POST)
public Observable<CustomerResponse> createAccount(@Validated @RequestBody CustomerInfo request) {
public Observable<CustomerResponse> createCustomer(@Validated @RequestBody CustomerInfo request) {
return customerService.createCustomer(request)
.map(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityIdentifier().getId(), request));
}
@RequestMapping(value = "/{id}/toaccounts", method = RequestMethod.POST)
public Observable<ResponseEntity<?>> addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountsRequest request) {
return customerService.addToAccount(id, request.getId(), request.getTitle(), request.getOwner())
.map(entityAndEventInfo -> ResponseEntity.ok().build());
}
}

View File

@@ -0,0 +1,43 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers;
/**
* Created by Main on 08.02.2016.
*/
public class ToAccountsRequest {
private String id;
private String title;
private String owner;
public ToAccountsRequest() {
}
public ToAccountsRequest(String id, String title, String owner) {
this.id = id;
this.title = title;
this.owner = owner;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
}

View File

@@ -3,6 +3,13 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.cu
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import java.util.Collections;
import static org.springframework.data.mongodb.core.query.Criteria.where;
/**
* Created by Main on 04.02.2016.
@@ -11,19 +18,25 @@ public class CustomerInfoUpdateService {
private Logger logger = LoggerFactory.getLogger(getClass());
private CustomerInfoRepository accountInfoRepository;
private QuerySideCustomerRepository accountInfoRepository;
private MongoTemplate mongoTemplate;
public CustomerInfoUpdateService(CustomerInfoRepository accountInfoRepository) {
public CustomerInfoUpdateService(QuerySideCustomerRepository accountInfoRepository, MongoTemplate mongoTemplate) {
this.accountInfoRepository = accountInfoRepository;
this.mongoTemplate = mongoTemplate;
}
public void create(String id, CustomerInfo customerInfo) {
try {
accountInfoRepository.save(new CustomerInfoWithId(id,
customerInfo.getEmail(),
customerInfo.getSsn(),
customerInfo.getPhoneNumber(),
customerInfo.getAddress())
accountInfoRepository.save(new QuerySideCustomer(id,
"",
"",
customerInfo.getEmail(),
customerInfo.getSsn(),
customerInfo.getPhoneNumber(),
customerInfo.getAddress(),
Collections.<ToAccountInfo>emptyList()
)
);
logger.info("Saved in mongo");
} catch (Throwable t) {
@@ -32,4 +45,11 @@ public class CustomerInfoUpdateService {
}
}
public void addToAccount(String id, ToAccountInfo accountInfo) {
mongoTemplate.updateMulti(new Query(where("id").is(id)),
new Update().
push("toAccounts", accountInfo),
QuerySideCustomer.class);
}
}

View File

@@ -1,20 +0,0 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
/**
* Created by Main on 05.02.2016.
*/
public class CustomerInfoWithId extends CustomerInfo {
private String id;
public CustomerInfoWithId(String id, String email, String ssn, String phoneNumber, Address address) {
super(email, ssn, phoneNumber, address);
this.id = id;
}
public String getId() {
return id;
}
}

View File

@@ -7,22 +7,22 @@ import java.util.List;
public class CustomerQueryService {
private CustomerInfoRepository customerInfoRepository;
private QuerySideCustomerRepository querySideCustomerRepository;
public CustomerQueryService(CustomerInfoRepository customerInfoRepository) {
this.customerInfoRepository = customerInfoRepository;
public CustomerQueryService(QuerySideCustomerRepository querySideCustomerRepository) {
this.querySideCustomerRepository = querySideCustomerRepository;
}
public Observable<CustomerInfoWithId> findByCustomerId(EntityIdentifier customerId) {
CustomerInfoWithId customer = customerInfoRepository.findOne(customerId.getId());
public Observable<QuerySideCustomer> findByCustomerId(EntityIdentifier customerId) {
QuerySideCustomer customer = querySideCustomerRepository.findOne(customerId.getId());
if (customer == null)
return Observable.error(new CustomerNotFoundException(customerId.getId()));
else
return Observable.just(customer);
}
public Observable<List<CustomerInfoWithId>> findByEmail(String email){
List<CustomerInfoWithId> customers = customerInfoRepository.findByEmailLike(email);
public Observable<List<QuerySideCustomer>> findByEmail(String email){
List<QuerySideCustomer> customers = querySideCustomerRepository.findByEmailLike(email);
if (customers.isEmpty())
return Observable.error(new CustomersNotFoundException());
else

View File

@@ -1,5 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerAddedToAccount;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerCreatedEvent;
import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler;
import net.chrisrichardson.eventstore.subscriptions.DispatchedEvent;
@@ -28,10 +29,21 @@ public class CustomerQueryWorkflow implements CompoundEventHandler {
public Observable<Object> create(DispatchedEvent<CustomerCreatedEvent> de) {
CustomerCreatedEvent event = de.event();
String id = de.getEntityIdentifier().getId();
String eventId = de.eventId().asString();
logger.info("**************** customer version=" + id + ", " + eventId);
customerInfoUpdateService.create(id, event.getCustomerInfo());
return Observable.just(null);
}
@EventHandlerMethod
public Observable<Object> addToAccount(DispatchedEvent<CustomerAddedToAccount> de) {
CustomerAddedToAccount event = de.event();
String id = de.getEntityIdentifier().getId();
ToAccountInfo toAccountInfo = new ToAccountInfo(event.getAccountId(),
event.getTitle(),
event.getAccountOwner());
customerInfoUpdateService.addToAccount(id, toAccountInfo);
return Observable.just(null);
}
}

View File

@@ -0,0 +1,40 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
import java.util.List;
/**
* Created by Main on 05.02.2016.
*/
public class QuerySideCustomer extends CustomerInfo {
private String id;
protected String firstName;
protected String lastName;
private List<ToAccountInfo> toAccounts;
public QuerySideCustomer(String id, String firstName, String lastName, String email, String ssn, String phoneNumber, Address address, List<ToAccountInfo> toAccounts) {
super(email, ssn, phoneNumber, address);
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.toAccounts = toAccounts;
}
public String getId() {
return id;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public List<ToAccountInfo> getToAccounts() {
return toAccounts;
}
}

View File

@@ -19,12 +19,12 @@ public class QuerySideCustomerConfiguration {
}
@Bean
public CustomerInfoUpdateService customerInfoUpdateService(CustomerInfoRepository customerInfoRepository) {
return new CustomerInfoUpdateService(customerInfoRepository);
public CustomerInfoUpdateService customerInfoUpdateService(QuerySideCustomerRepository querySideCustomerRepository) {
return new CustomerInfoUpdateService(querySideCustomerRepository);
}
@Bean
public CustomerQueryService customerQueryService(CustomerInfoRepository accountInfoRepository) {
public CustomerQueryService customerQueryService(QuerySideCustomerRepository accountInfoRepository) {
return new CustomerQueryService(accountInfoRepository);
}

View File

@@ -4,7 +4,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
interface CustomerInfoRepository extends MongoRepository<CustomerInfoWithId, String> {
interface QuerySideCustomerRepository extends MongoRepository<QuerySideCustomer, String> {
List<CustomerInfoWithId> findByEmailLike(String email);
List<QuerySideCustomer> findByEmailLike(String email);
}

View File

@@ -0,0 +1,29 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
/**
* Created by Main on 08.02.2016.
*/
public class ToAccountInfo {
private String id;
private String title;
private String owner;
public ToAccountInfo(String id, String title, String owner) {
this.id = id;
this.title = title;
this.owner = owner;
}
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public String getOwner() {
return owner;
}
}

View File

@@ -1,7 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.customers;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomerInfoWithId;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.QuerySideCustomer;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomerNotFoundException;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomerQueryService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomersNotFoundException;
@@ -52,14 +52,14 @@ public class CustomerQueryController {
}
private CustomerResponse getCustomerResponse(CustomerInfoWithId customerInfoWithId) {
return new CustomerResponse(customerInfoWithId.getId(), new CustomerInfo(customerInfoWithId.getEmail(),
customerInfoWithId.getSsn(),
customerInfoWithId.getPhoneNumber(),
customerInfoWithId.getAddress()));
private CustomerResponse getCustomerResponse(QuerySideCustomer querySideCustomer) {
return new CustomerResponse(querySideCustomer.getId(), new CustomerInfo(querySideCustomer.getEmail(),
querySideCustomer.getSsn(),
querySideCustomer.getPhoneNumber(),
querySideCustomer.getAddress()));
}
private CustomersQueryResponse getCustomersQueryResponse(List<CustomerInfoWithId> customersList) {
private CustomersQueryResponse getCustomersQueryResponse(List<QuerySideCustomer> customersList) {
return new CustomersQueryResponse(customersList
.stream()
.map(this::getCustomerResponse)

View File

@@ -272,6 +272,47 @@
}
}
}
},
"/customers/{id}/toaccounts": {
"post": {
"tags": [
"customer-service-command-side-controller"
],
"summary": "addToAccount",
"operationId": "addToAccountUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"name": "id",
"in": "path",
"description": "id",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "request",
"description": "request",
"required": true,
"schema": {
"$ref": "#/definitions/ToAccountsRequest"
}
}
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Validation error"
}
}
}
}
},
"definitions": {
@@ -376,6 +417,20 @@
}
}
},
"ToAccountsRequest":{
"required": [ "id", "owner" ],
"properties": {
"id": {
"type": "string"
},
"title": {
"type": "string"
},
"owner": {
"type": "string"
}
}
},
"Address": {
"properties": {
"street1": {
@@ -392,7 +447,7 @@
},
"zipCode": {
"type": "string"
},
}
}
}
}

View File

@@ -32,4 +32,5 @@ include 'customers-query-side-web'
include 'common-customers'
include 'customers-command-side-service'
include 'customers-query-side-service'
include 'common-auth-controller'