Created
November 18, 2022 08:43
-
-
Save MavoCz/018ad4c575eb964b650cbf4efa4c1b71 to your computer and use it in GitHub Desktop.
Item update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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