Skip to content

Instantly share code, notes, and snippets.

@MavoCz
Created November 18, 2022 08:43
Show Gist options
  • Save MavoCz/018ad4c575eb964b650cbf4efa4c1b71 to your computer and use it in GitHub Desktop.
Save MavoCz/018ad4c575eb964b650cbf4efa4c1b71 to your computer and use it in GitHub Desktop.
Item update
@PutMapping("/{id}")
fun update(@PathVariable("id") id: Long, @RequestBody itemDto: CreateItemDto) {
itemRepository.update(id, itemDto) {
it.updatedOn = LocalDateTime.now()
}
}
fun update(id: Long, dto: Any, change: Consumer<R>) {
val record : R = dsl.newRecord(table, dto)
change.accept (record)
update(id, record)
}
fun update(id: Long, updatedRecord: R) {
val count = dsl.update(table)
.set(updatedRecord)
.where(idField.eq(id))
.execute()
if (count != 1) throw NotFoundException("No record was updated")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment