Created
January 25, 2017 11:41
-
-
Save gytis/8d67c2389de028291cefb8d091dd9fb7 to your computer and use it in GitHub Desktop.
Blog :: New Narayana release and Spring Boot quickstart :: Sell operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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