use of com.redhat.training.bank.model.BankAccount in project AD482-apps by RedHatTraining.
the class AccountResource method deposit.
@PUT
@Path("{id}/deposit")
@Transactional
public BankAccount deposit(@PathParam Long id, DepositAmountInBankAccount deposit) {
if (deposit.id == null) {
throw new WebApplicationException("Bank Account ID was not set on request.", Response.Status.BAD_REQUEST);
}
if (deposit.amount <= 0) {
throw new WebApplicationException("Unprocessable amount on request.", Response.Status.BAD_REQUEST);
}
BankAccount entity = BankAccount.findById(id);
if (entity == null) {
throw new WebApplicationException("Bank Account with id of " + id + " does not exist.", Response.Status.NOT_FOUND);
}
entity.balance = entity.balance + deposit.amount;
return entity;
}
use of com.redhat.training.bank.model.BankAccount in project AD482-apps by RedHatTraining.
the class AccountResource method withdraw.
@PUT
@Path("{id}/withdraw")
@Transactional
public BankAccount withdraw(@PathParam Long id, WithdrawAmountFromBankAccount withdraw) {
if (withdraw.id == null) {
throw new WebApplicationException("Bank Account ID was not set on request.", Response.Status.BAD_REQUEST);
}
if (withdraw.amount <= 0) {
throw new WebApplicationException("Unprocessable amount on request.", Response.Status.BAD_REQUEST);
}
BankAccount entity = BankAccount.findById(id);
if (entity == null) {
throw new WebApplicationException("Bank Account with id of " + id + " does not exist.", Response.Status.NOT_FOUND);
}
if (entity.balance < withdraw.amount) {
throw new WebApplicationException("Insufficient funds for withdraw.", Response.Status.CONFLICT);
}
entity.balance = entity.balance - withdraw.amount;
return entity;
}
use of com.redhat.training.bank.model.BankAccount in project AD482-apps by RedHatTraining.
the class AccountResource method delete.
@DELETE
@Path("{id}")
@Transactional
public Response delete(@PathParam Long id) {
BankAccount entity = BankAccount.findById(id);
if (entity == null) {
throw new WebApplicationException("Bank Account with id of " + id + " does not exist.", Response.Status.NOT_FOUND);
}
entity.delete();
LOGGER.info("Deleted bank account - ID: " + id);
return Response.status(Response.Status.NO_CONTENT).build();
}
use of com.redhat.training.bank.model.BankAccount in project AD482-apps by RedHatTraining.
the class NewBankAccountConsumer method processMessage.
// TODO: Create the consumer implementation
@Incoming("new-bank-account-in")
@Blocking
@Transactional
public void processMessage(NewBankAccount message) {
BankAccount entity = BankAccount.findById(message.getId());
if (entity != null) {
entity.profile = message.getBalance() < 100000 ? "regular" : "premium";
LOGGER.info("Updated Bank Account - ID: " + message.getId() + " - Type: " + entity.profile);
} else {
LOGGER.info("Bank Account not found!");
}
}
use of com.redhat.training.bank.model.BankAccount in project AD482-apps by RedHatTraining.
the class AccountResource method depositAmountInBankAccount.
@Transactional
public BankAccount depositAmountInBankAccount(Long bankAccountId, DepositAmountInBankAccount deposit) {
if (deposit.bankAccountId == null || !deposit.bankAccountId.equals(bankAccountId)) {
throw new WebApplicationException("Bank Account ID was not set on request.", Response.Status.BAD_REQUEST);
}
if (deposit.amount == null || deposit.amount <= 0) {
throw new WebApplicationException("Unprocessable amount on request.", Response.Status.BAD_REQUEST);
}
BankAccount entity = BankAccount.findById(bankAccountId);
if (entity == null) {
throw new WebApplicationException("Bank Account with id of " + bankAccountId + " does not exist.", Response.Status.NOT_FOUND);
}
entity.balance = entity.balance + deposit.amount;
return entity;
}
Aggregations