예제 #1
0
 /**
  * POST /expenses : Create a new expense.
  *
  * @param expense the expense to create
  * @return the ResponseEntity with status 201 (Created) and with body the new expense, or with
  *     status 400 (Bad Request) if the expense has already an ID
  * @throws URISyntaxException if the Location URI syntax is incorrect
  */
 @RequestMapping(
     value = "/expenses",
     method = RequestMethod.POST,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Expense> createExpense(@Valid @RequestBody Expense expense)
     throws URISyntaxException {
   log.debug("REST request to save Expense : {}", expense);
   if (expense.getId() != null) {
     return ResponseEntity.badRequest()
         .headers(
             HeaderUtil.createFailureAlert(
                 "expense", "idexists", "A new expense cannot already have an ID"))
         .body(null);
   }
   calculationService.addExpense(expense);
   Expense result = expenseRepository.save(expense);
   return ResponseEntity.created(new URI("/api/expenses/" + result.getId()))
       .headers(HeaderUtil.createEntityCreationAlert("expense", result.getId().toString()))
       .body(result);
 }