Add expense/income update

This commit is contained in:
Dmitrii Cravcenco
2023-10-27 17:53:00 +03:00
parent 6fc12d22b5
commit eb2d0e53dc
2 changed files with 20 additions and 13 deletions

View File

@@ -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();
}