Merge last changes from 'remotes/upstream/wip-customer' into wip-customer
This commit is contained in:
@@ -18,13 +18,13 @@ public class AccountInfo {
|
||||
private String description;
|
||||
private long balance;
|
||||
private List<AccountChangeInfo> changes;
|
||||
private Map<String, AccountTransactionInfo> transactions;
|
||||
private List<AccountTransactionInfo> transactions;
|
||||
private String version;
|
||||
|
||||
private AccountInfo() {
|
||||
}
|
||||
|
||||
public AccountInfo(String id, String customerId, String title, String description, long balance, List<AccountChangeInfo> changes, Map<String, 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;
|
||||
@@ -57,11 +57,11 @@ public class AccountInfo {
|
||||
}
|
||||
|
||||
public List<AccountChangeInfo> getChanges() {
|
||||
return changes == null ? Collections.EMPTY_LIST : changes;
|
||||
return changes;
|
||||
}
|
||||
|
||||
public List<AccountTransactionInfo> getTransactions() {
|
||||
return transactions == null ? Collections.EMPTY_LIST : new ArrayList<>(transactions.values());
|
||||
return transactions;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
|
||||
@@ -17,35 +17,40 @@ import static org.springframework.data.mongodb.core.query.Criteria.where;
|
||||
public class AccountInfoUpdateService {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private AccountInfoRepository accountInfoRepository;
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
public AccountInfoUpdateService(MongoTemplate mongoTemplate) {
|
||||
public AccountInfoUpdateService(AccountInfoRepository accountInfoRepository, MongoTemplate mongoTemplate) {
|
||||
this.accountInfoRepository = accountInfoRepository;
|
||||
this.mongoTemplate = mongoTemplate;
|
||||
}
|
||||
|
||||
|
||||
public void create(String accountId, String customerId, String title, BigDecimal initialBalance, String description, String version) {
|
||||
try {
|
||||
WriteResult x = mongoTemplate.upsert(new Query(where("id").is(accountId).and("version").exists(false)),
|
||||
new Update()
|
||||
.set("customerId", customerId)
|
||||
.set("title", title)
|
||||
.set("description", description)
|
||||
.set("balance", toIntegerRepr(initialBalance))
|
||||
.set("version", version),
|
||||
AccountInfo.class);
|
||||
accountInfoRepository.save(new AccountInfo(
|
||||
accountId,
|
||||
customerId,
|
||||
title,
|
||||
description,
|
||||
toIntegerRepr(initialBalance),
|
||||
Collections.<AccountChangeInfo>emptyList(),
|
||||
Collections.<AccountTransactionInfo>emptyList(),
|
||||
version));
|
||||
logger.info("Saved in mongo");
|
||||
} catch (Throwable t) {
|
||||
logger.error("Error during saving: ");
|
||||
logger.error("Error during saving: ", t);
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addTransaction(String eventId, String accountId, AccountTransactionInfo ti) {
|
||||
mongoTemplate.upsert(new Query(where("id").is(accountId)),
|
||||
public void addTransaction(String eventId, String fromAccountId, AccountTransactionInfo ti) {
|
||||
mongoTemplate.updateMulti(new Query(where("id").is(fromAccountId)), /* wrong .and("version").lt(eventId) */
|
||||
new Update().
|
||||
set("transactions." + eventId, ti),
|
||||
push("transactions", ti).
|
||||
set("version", eventId),
|
||||
AccountInfo.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ public class QuerySideAccountConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountInfoUpdateService accountInfoUpdateService(MongoTemplate mongoTemplate) {
|
||||
return new AccountInfoUpdateService(mongoTemplate);
|
||||
public AccountInfoUpdateService accountInfoUpdateService(AccountInfoRepository accountInfoRepository, MongoTemplate mongoTemplate) {
|
||||
return new AccountInfoUpdateService(accountInfoRepository, mongoTemplate);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -27,8 +27,6 @@ public class QuerySideAccountConfiguration {
|
||||
return new AccountQueryService(accountInfoRepository);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public QuerySideDependencyChecker querysideDependencyChecker(MongoTemplate mongoTemplate) {
|
||||
return new QuerySideDependencyChecker(mongoTemplate);
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.t
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
||||
@Configuration
|
||||
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
||||
@Configuration
|
||||
@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, EventuateHttpStompClientConfiguration.class, QuerySideWebConfiguration.class, CustomersQuerySideWebConfiguration.class, CustomersCommandSideWebConfiguration.class, AuthConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class BankingWebConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.List;
|
||||
@Configuration
|
||||
@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, EventuateJdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class, CustomersQuerySideWebConfiguration.class, CustomersCommandSideWebConfiguration.class, AuthConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class BankingWebTestConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user