Exemplo n.º 1
0
 /**
  * PUT /expenses : Updates an existing expense.
  *
  * @param expense the expense to update
  * @return the ResponseEntity with status 200 (OK) and with body the updated expense, or with
  *     status 400 (Bad Request) if the expense is not valid, or with status 500 (Internal Server
  *     Error) if the expense couldnt be updated
  * @throws URISyntaxException if the Location URI syntax is incorrect
  */
 @RequestMapping(
     value = "/expenses",
     method = RequestMethod.PUT,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Expense> updateExpense(@Valid @RequestBody Expense expense)
     throws URISyntaxException {
   log.debug("REST request to update Expense : {}", expense);
   if (expense.getId() == null) {
     return createExpense(expense);
   }
   calculationService.updateExpense(expense);
   Expense result = expenseRepository.save(expense);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityUpdateAlert("expense", expense.getId().toString()))
       .body(result);
 }
Exemplo n.º 2
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);
 }