/*
 * Copyright (c) 2017 General Electric Company. All rights reserved.
 *
 * The copyright to the computer software herein is the property of General Electric Company.
 * The software may be used and/or copied only with the written permission of
 * General Electric Company or in accordance with the terms and conditions stipulated in the
 * agreement/contract under which the software has been supplied.
 */

package org.axonframework.sample.axonbank.myaxonbank;

import org.axonframework.commandhandling.CommandBus;
import org.axonframework.sample.axonbank.myaxonbank.coreapi.CreateAccountCommand;
import org.axonframework.sample.axonbank.myaxonbank.coreapi.WithdrawMoneyCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static org.axonframework.commandhandling.GenericCommandMessage.asCommandMessage;

@RestController
public class MyController {

  @Autowired
  private CommandBus commandBus;

  @RequestMapping(value = "/hello")
  public String say() {
    System.out.println("Command Bus>>>>" + commandBus);
    commandBus.dispatch(asCommandMessage(new CreateAccountCommand("1234", 1000)));
    commandBus.dispatch(asCommandMessage(new WithdrawMoneyCommand("1234", 800)));
    return "Hello!";

  }
}

@@ -500,26 +500,38 @@
 andling.
-CommandBus
+gateway.CommandGateway
 ;%0Aimport
@@ -882,97 +882,8 @@
 r;%0A%0A
-import static org.axonframework.commandhandling.GenericCommandMessage.asCommandMessage;%0A%0A
 @Res
@@ -957,19 +957,23 @@
 mand
-Bus
+Gateway
  command
 Bus;
@@ -968,19 +968,23 @@
  command
-Bus
+Gateway
 ;%0A%0A  @Re
@@ -1046,118 +1046,110 @@
     
-System.out.println(%22Command Bus%3E%3E%3E%3E%22 + commandBus);%0A    commandBus.dispatch(asCommandMessage(new CreateAccount
+commandGateway.send(new CreateAccountCommand(%221234%22, 1000));%0A    commandGateway.send(new WithdrawMoney
 Comm
@@ -1164,15 +1164,13 @@
 4%22, 
-10
+8
 00))
-)
 ;%0A  
@@ -1182,37 +1182,20 @@
 mand
-Bus.dispatch(asCommandMessage
+Gateway.send
 (new
@@ -1228,14 +1228,13 @@
 4%22, 
-8
+5
 00))
-)
 ;%0A  

Use command gateway instead of command bus to generate commands