Return full transaction object for individual transactions
Signed-off-by: Billy Brawner <billy@wbrawner.com>
This commit is contained in:
parent
93be762dad
commit
17ad169fe1
1 changed files with 6 additions and 6 deletions
|
@ -90,11 +90,11 @@ class TransactionController @Autowired constructor(
|
||||||
|
|
||||||
@GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
|
@GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||||
@ApiOperation(value = "getTransaction", nickname = "getTransaction", tags = ["Transactions"])
|
@ApiOperation(value = "getTransaction", nickname = "getTransaction", tags = ["Transactions"])
|
||||||
fun getTransaction(@PathVariable id: Long): ResponseEntity<TransactionResponse> {
|
fun getTransaction(@PathVariable id: Long): ResponseEntity<Transaction> {
|
||||||
val transaction = transactionRepository.findById(id).orElse(null) ?: return ResponseEntity.notFound().build()
|
val transaction = transactionRepository.findById(id).orElse(null) ?: return ResponseEntity.notFound().build()
|
||||||
budgetRepository.findByUsersContainsAndTransactionsContains(getCurrentUser()!!, transaction).orElse(null)
|
budgetRepository.findByUsersContainsAndTransactionsContains(getCurrentUser()!!, transaction).orElse(null)
|
||||||
?: return ResponseEntity.notFound().build()
|
?: return ResponseEntity.notFound().build()
|
||||||
return ResponseEntity.ok(TransactionResponse(transaction))
|
return ResponseEntity.ok(transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@ -107,7 +107,7 @@ class TransactionController @Autowired constructor(
|
||||||
val category: Category? = request.categoryId?.let {
|
val category: Category? = request.categoryId?.let {
|
||||||
categoryRepository.findByBudgetAndId(budget, request.categoryId).orElse(null)
|
categoryRepository.findByBudgetAndId(budget, request.categoryId).orElse(null)
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(TransactionResponse(transactionRepository.save(Transaction(
|
return ResponseEntity.ok(transactionRepository.save(Transaction(
|
||||||
title = request.title,
|
title = request.title,
|
||||||
description = request.description,
|
description = request.description,
|
||||||
date = Instant.parse(request.date),
|
date = Instant.parse(request.date),
|
||||||
|
@ -116,12 +116,12 @@ class TransactionController @Autowired constructor(
|
||||||
expense = request.expense,
|
expense = request.expense,
|
||||||
budget = budget,
|
budget = budget,
|
||||||
createdBy = getCurrentUser()!!
|
createdBy = getCurrentUser()!!
|
||||||
))))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}", consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE])
|
@PutMapping("/{id}", consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||||
@ApiOperation(value = "updateTransaction", nickname = "updateTransaction", tags = ["Transactions"])
|
@ApiOperation(value = "updateTransaction", nickname = "updateTransaction", tags = ["Transactions"])
|
||||||
fun updateTransaction(@PathVariable id: Long, @RequestBody request: UpdateTransactionRequest): ResponseEntity<TransactionResponse> {
|
fun updateTransaction(@PathVariable id: Long, @RequestBody request: UpdateTransactionRequest): ResponseEntity<Transaction> {
|
||||||
var transaction = transactionRepository.findById(id).orElse(null) ?: return ResponseEntity.notFound().build()
|
var transaction = transactionRepository.findById(id).orElse(null) ?: return ResponseEntity.notFound().build()
|
||||||
var budget = budgetRepository.findByUsersContainsAndTransactionsContains(getCurrentUser()!!, transaction)
|
var budget = budgetRepository.findByUsersContainsAndTransactionsContains(getCurrentUser()!!, transaction)
|
||||||
.orElse(null) ?: return ResponseEntity.notFound().build()
|
.orElse(null) ?: return ResponseEntity.notFound().build()
|
||||||
|
@ -141,7 +141,7 @@ class TransactionController @Autowired constructor(
|
||||||
transaction = transaction.copy(category = category)
|
transaction = transaction.copy(category = category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(TransactionResponse(transactionRepository.save(transaction)))
|
return ResponseEntity.ok(transactionRepository.save(transaction))
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}", produces = [MediaType.TEXT_PLAIN_VALUE])
|
@DeleteMapping("/{id}", produces = [MediaType.TEXT_PLAIN_VALUE])
|
||||||
|
|
Loading…
Reference in a new issue