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();
}
Aggregations