Skip to content

Instantly share code, notes, and snippets.

@erdemaydin
Last active July 14, 2021 14:22
Show Gist options
  • Select an option

  • Save erdemaydin/fb1b096279cc714f998c63eea87180fd to your computer and use it in GitHub Desktop.

Select an option

Save erdemaydin/fb1b096279cc714f998c63eea87180fd to your computer and use it in GitHub Desktop.
updateTask
@PutMapping( "/tasks/{id}")
public ResponseEntity<Task> updateTask(@PathVariable Long id, @RequestBody Task requestTask) {
log.info("updating task with id " + id);
if (StringUtils.isEmpty(requestTask.getDescription())) {
throw new InvalidInputException("Description can not be empty");
}
Optional<Task> optCurrentTask = taskService.findById(id);
if (!optCurrentTask.isPresent()) {
throw new RecordNotFoundException("task id "+ id + " doesn't found");
}
Task currentTask = optCurrentTask.get();
currentTask.setDescription(requestTask.getDescription());
currentTask.setPriority(requestTask.getPriority());
taskService.save(currentTask);
log.info("updating task with id " + id + "finish success");
return ResponseEntity.ok(currentTask);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment