package com.mytutorial.controller;
import java.math.BigDecimal;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.mytutorial.model.Account;
@Controller
@RequestMapping("/v1/forecasting")
public class AccountController {
@RequestMapping(value = "/accounts", method = RequestMethod.GET, produces={MediaType.APPLICATION_JSON_VALUE})
public @ResponseBody Account[] getAccounts() {
Account[] accounts = new Account[] { new Account("123", "John R", BigDecimal.valueOf(235.00)),
new Account("345", "Peter J", BigDecimal.valueOf(2505.60)) };
return accounts;
}
@RequestMapping(value = "/account/{id}", method = RequestMethod.GET, produces={MediaType.APPLICATION_XML_VALUE})
public @ResponseBody Account getAccount(@PathVariable("id") String id) {
//TODO: go to database and get the Account by id
Account account = new Account(id, "John R", BigDecimal.valueOf(235.00));
return account;
}
@RequestMapping(value = "/account", method = RequestMethod.POST)
public ResponseEntity<Account> saveAccount(@RequestBody Account account) {
System.out.println("Creating:" + account);
//TODO: Save to database
return new ResponseEntity<Account>(account, HttpStatus.OK);
}
}