Skip to content

Instantly share code, notes, and snippets.

@gytis
Created January 25, 2017 11:41
Show Gist options
  • Save gytis/8d67c2389de028291cefb8d091dd9fb7 to your computer and use it in GitHub Desktop.
Save gytis/8d67c2389de028291cefb8d091dd9fb7 to your computer and use it in GitHub Desktop.
Blog :: New Narayana release and Spring Boot quickstart :: Sell operation
@DeleteMapping("/portfolio/{username}/{symbol}")
@Transactional
public void sell(@PathVariable String username, @PathVariable String symbol, @RequestParam("amount") int amount) {
User user = getUser(username);
Share share = getShare(symbol);
PortfolioEntry portfolioEntry = getPortfolioEntry(user, share);
updateBudget(user, amount * share.getPrice()); // Increase user's budget
updateSharesAmount(share, amount); // Increase shares amount available for sale
updatePortfolioEntry(portfolioEntry, -1 * amount); // Decrease shares amount owned by the user
sendUpdate(String.format("'%s' just sold %d shares of '%s' for the amount of %d", username, amount, symbol,
amount * share.getPrice()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment