R1
Code review round. Review the code for 30 minutes, add comments in the same google doc. Discuss the top 5 issues.
import org.slf4j.Logger:
import org.slf4j.LoggerFactory:
import org.springframework.beans.factory.annotation.Antowired:
/**
Creating a new version of the borrowing functionality that registers the loan in a 3rd party Loan Management System (wrapped in feign client service). Since we get a lot of errors from the 3rd party I've added a functionality to let our staff move the money on behalf of the user if they give us a call that something's not working properly!!! */
eRequestMapping("/v3/accounts/")
@RestController
public class LoanV3Controller (
@Autowired
public AccountService accountService:
@Autowired
public LoanManagement Service externalLMS:
I
public static final Logger logger = LoggerFactory.getLogger(LoanV3Controller.class):
@PutMapping (value = "/new/taccountId}/v2/loans/borrow")
public void borrowMoney (@PathVariable String accountId
@RequestParam boolean isAdminAgent @RequestParam double loanAmount @Request Param String sourceAccountId) {
// for admins we don't need to check the ownership
if (!isAdminAgent) {
Account acc = accountService.getAccount (accountId)
if (acc.getOwner () != AuthContext.getCurrentUserID()) {
throw new InternalServerError();
}
}
// make sure the user is allowed to borrow this amount
if (loanAmount < externalLMS.getCreditLimit (accountId)) {
Account sourceAccount accountService.getAccount (sourceAccountId); Account destinationAccount = accountService.getAccount (accountId);
Optional.ofNullable = (sourceAccount).orElseThrow();
double balance = sourceAccount.getBalance();
if (balance > loanAmount) (
accountService. disburse (sourceAccount, destinationAccount, loanAmount);
externalLMS.registerLoan (
String.valueOf(new Random().nextInt(1000000)), loanAmount,
AuthContext.getCurrentUserID ());
else {
throw new InternalServerError();
}
}
}Comments (0)

