- added title and description fields to accountInfo

- added GET /accounts?customerId=XXX endpoint
- refactored tests
This commit is contained in:
dartpopikyardo
2016-03-15 20:10:58 +03:00
parent 28216a082d
commit b16039ee53
21 changed files with 120 additions and 46 deletions

View File

@@ -10,6 +10,7 @@ public class AccountInfo {
private String id;
private String customerId;
private String title;
private String description;
private long balance;
private List<AccountChangeInfo> changes;
private List<AccountTransactionInfo> transactions;
@@ -18,11 +19,12 @@ public class AccountInfo {
private AccountInfo() {
}
public AccountInfo(String id, String customerId, String title, long balance, List<AccountChangeInfo> changes, List<AccountTransactionInfo> transactions, String version) {
public AccountInfo(String id, String customerId, String title, String description, long balance, List<AccountChangeInfo> changes, List<AccountTransactionInfo> transactions, String version) {
this.id = id;
this.customerId = customerId;
this.title = title;
this.description = description;
this.balance = balance;
this.changes = changes;
this.transactions = transactions;
@@ -41,6 +43,10 @@ public class AccountInfo {
return title;
}
public String getDescription() {
return description;
}
public long getBalance() {
return balance;
}

View File

@@ -2,5 +2,9 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.ac
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
interface AccountInfoRepository extends MongoRepository<AccountInfo, String> {
List<AccountInfo> findByCustomerId(String customerId);
}

View File

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

View File

@@ -3,8 +3,11 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.ac
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.EntityNotFoundException;
import org.springframework.dao.EmptyResultDataAccessException;
import rx.Observable;
import java.util.List;
public class AccountQueryService {
private AccountInfoRepository accountInfoRepository;
@@ -20,4 +23,12 @@ public class AccountQueryService {
else
return Observable.just(account);
}
public Observable<List<AccountInfo>> findByCustomerId(String customerId) {
List<AccountInfo> result = accountInfoRepository.findByCustomerId(customerId);
if(result.isEmpty())
return Observable.error(new EmptyResultDataAccessException(1));
else
return Observable.just(result);
}
}

View File

@@ -39,7 +39,8 @@ public class AccountQueryWorkflow implements CompoundEventHandler {
BigDecimal initialBalance = event.getInitialBalance();
String customerId = event.getCustomerId();
String title = event.getTitle();
accountInfoUpdateService.create(id, customerId, title, initialBalance, eventId);
String description = event.getDescription();
accountInfoUpdateService.create(id, customerId, title, initialBalance, description, eventId);
return Observable.just(null);
}