public static Result sellStock(int gameId) {
GameCheck gc = new GameCheck(gameId, false);
if (gc.hasErrors) {
return gc.getResult();
}
GamePlayer me = gc.currentGame.getPlayerInGame(UserManager.getCurrentLoggedInUser());
Form<SellStock> sellStockForm = Form.form(SellStock.class).bindFromRequest();
response().setContentType("application/json");
if(sellStockForm.hasErrors()){
return badRequest(sellStockForm.errorsAsJson());
}else{
SellStock sellStock = sellStockForm.get();
//play.Logger.info("Price: "+sellStock.price);
if(me.sellStock(sellStock.ticker, sellStock.quantity, sellStock.price)){
return ok(GameStateJSONFormatter.getGameStateJson(gameId));
}else{
return badRequest("{error: \"could not make sale!\"}");
}
}