Skip to content
Snippets Groups Projects
Commit cb4d4c21 authored by Filip Piták's avatar Filip Piták
Browse files

Implement service for processing remote calls

parent 3ea1a2f5
No related branches found
No related tags found
No related merge requests found
......@@ -36,18 +36,18 @@ public interface DtoMapper {
default ProcessDto map(Process source) {
ProcessDto dto = new ProcessDto();
dto.setIdentifier(source.uuid());
dto.setIdentifier(source.getUuid());
dto.setStatus(map(source.getStatus()));
dto.setInfo(source.getStatusInformation());
dto.setInfo(source.getInformation());
return dto;
}
default ProcessDetailDto map(Process process, Transaction transaction) {
ProcessDetailDto dto = new ProcessDetailDto();
dto.identifier(process.uuid());
dto.identifier(process.getUuid());
dto.status(map(process.getStatus()));
dto.info(process.getStatusInformation());
dto.info(process.getInformation());
dto.source(map(transaction.getSource()));
if (transaction.getTarget() != null) {
......
package cz.muni.pa165.banking.application.proxy;
import cz.muni.pa165.banking.account.management.AccountApi;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(url = "${banking.apps.management.url}", name = "AccountApi")
public interface AccountApiProxy extends AccountApi {
}
package cz.muni.pa165.banking.application.proxy;
import cz.muni.pa165.banking.account.query.SystemServiceApi;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(url = "${banking.apps.query.url}", name = "SystemServiceApi")
public interface SystemServiceApiProxy extends SystemServiceApi {
}
package cz.muni.pa165.banking.application.service;
import cz.muni.pa165.banking.account.management.AccountApi;
import cz.muni.pa165.banking.account.management.dto.AccountDto;
import cz.muni.pa165.banking.account.query.CustomerServiceApi;
import cz.muni.pa165.banking.account.query.SystemServiceApi;
import cz.muni.pa165.banking.domain.account.Account;
import cz.muni.pa165.banking.domain.remote.AccountService;
import cz.muni.pa165.banking.domain.transaction.TransactionType;
......@@ -7,31 +11,54 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Currency;
import java.util.Objects;
import java.util.UUID;
@Service
public class AccountServiceImpl implements AccountService {
// TODO add proxies to other services of teammates and calls with validations
// -> Milestone2
private final AccountApi accountApi;
private final CustomerServiceApi publicBalanceApi;
private final SystemServiceApi privateBalanceApi;
public AccountServiceImpl(AccountApi accountApi, CustomerServiceApi publicBalanceApi, SystemServiceApi privateBalanceApi) {
this.accountApi = accountApi;
this.publicBalanceApi = publicBalanceApi;
this.privateBalanceApi = privateBalanceApi;
}
@Override
public Currency getAccountCurrency(Account account) {
return Currency.getInstance("EUR");
AccountDto accountDto = accountApi.findByAccountNumber(account.getAccountNumber()).getBody();
Objects.requireNonNull(accountDto);
return Currency.getInstance(accountDto.getCurrency());
}
@Override
public boolean isValid(Account account) {
return true;
AccountDto accountDto = accountApi.findByAccountNumber(account.getAccountNumber()).getBody();
return accountDto != null;
}
@Override
public boolean accountHasSufficientFunds(Account account, BigDecimal amount) {
return true;
BigDecimal currentBalance = publicBalanceApi.getBalance(account.getAccountNumber()).getBody();
return Objects.requireNonNull(currentBalance).compareTo(amount) >= 0;
}
@Override
public void publishAccountChange(UUID processUuid, TransactionType transactionType, BigDecimal amount, Account account, String information) {
public void publishAccountChange(UUID processUuid, TransactionType transactionType, BigDecimal amount, Account account) {
privateBalanceApi.addTransactionToBalance(
account.getAccountNumber(),
amount,
processUuid,
convertType(transactionType)
);
}
private cz.muni.pa165.banking.account.query.dto.TransactionType convertType(TransactionType type) {
return cz.muni.pa165.banking.account.query.dto.TransactionType.valueOf(type.name());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment