Last active
July 14, 2021 14:22
-
-
Save erdemaydin/fb1b096279cc714f998c63eea87180fd to your computer and use it in GitHub Desktop.
updateTask
This file contains hidden or 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( "/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