예제 #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);
 }
예제 #2
0
 /**
  * DELETE /expenses/:id : delete the "id" expense.
  *
  * @param id the id of the expense to delete
  * @return the ResponseEntity with status 200 (OK)
  */
 @RequestMapping(
     value = "/expenses/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Void> deleteExpense(@PathVariable Long id) {
   log.debug("REST request to delete Expense : {}", id);
   calculationService.removeExpense(id);
   expenseRepository.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("expense", id.toString()))
       .build();
 }
예제 #3
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);
 }