Fix category deletion

Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
William Brawner 2020-03-02 17:12:18 +00:00
parent 94d2111ca6
commit 0e7db87e16

View file

@ -125,11 +125,11 @@ open class CategoryController(
.orElse(null) .orElse(null)
?: return ResponseEntity.notFound().build() ?: return ResponseEntity.notFound().build()
val budget = budgets.first { it.id == category.budget!!.id } val budget = budgets.first { it.id == category.budget!!.id }
categoryRepository.delete(category)
transactionRepository.findAllByBudgetAndCategory(budget, category) transactionRepository.findAllByBudgetAndCategory(budget, category)
.forEach { transaction -> .forEach { transaction ->
transactionRepository.save(transaction.copy(category = null)) transactionRepository.save(transaction.copy(category = null))
} }
categoryRepository.delete(category)
return ResponseEntity.ok().build() return ResponseEntity.ok().build()
} }
} }