Add expense/income update
This commit is contained in:
@@ -61,14 +61,18 @@ public class ExpenseController {
|
||||
}
|
||||
|
||||
|
||||
// TODO: has to be checked on auto extracting Uuid
|
||||
@PatchMapping()
|
||||
public ResponseEntity<ExpenseDTO> updateExpense(@RequestBody ExpenseCreationDTO expenseDTO,
|
||||
// TODO: check if the expense belongs to the user
|
||||
@PatchMapping("/update/{id}")
|
||||
public ResponseEntity<Void> updateExpense(@PathVariable long id, @RequestBody ExpenseCreationDTO expenseDTO,
|
||||
BindingResult bindingResult) {
|
||||
Expense expense = expenseMapper.toExpense(expenseDTO);
|
||||
Expense expense = expenseService.getTransactionById(id);
|
||||
ExpenseCategory category = expenseCategoryService.getCategoryById(expenseDTO.getExpenseCategory());
|
||||
expense.setCategory(category);
|
||||
expense.setAmount(expenseDTO.getAmount());
|
||||
|
||||
if (!bindingResult.hasErrors()) {
|
||||
expenseService.createOrUpdate(expense);
|
||||
return ResponseEntity.ok(expenseMapper.toDto(expense));
|
||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user