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