diff --git a/src/main/java/com/example/demo/controller/TasksController.java b/src/main/java/com/example/demo/controller/TasksController.java index dd556456ee1b397931f3db74f5899875a46220fc..6700e5f44dd83977cb4769d7d4c646c821e43abd 100644 --- a/src/main/java/com/example/demo/controller/TasksController.java +++ b/src/main/java/com/example/demo/controller/TasksController.java @@ -122,16 +122,18 @@ public class TasksController { @ApiResponse(code = 200, message = "Task updated"), @ApiResponse(code = 500, message = "Unexpected application error") }) - @PutMapping + @PutMapping(path = "/{taskId}") public ResponseEntity<TaskDto> updateTask( @ApiParam(value = "Training definition ID", required = true) @PathVariable(name = "definitionId") Long definitionId, @ApiParam(value = "Game phase ID", required = true) @PathVariable(name = "phaseId") Long phaseId, + @ApiParam(value = "Task ID", required = true) + @PathVariable(name = "taskId") Long taskId, @ApiParam(value = "Task to be updated") @RequestBody @Valid TaskUpdateDto taskUpdateDto) { - TaskDto updatedTask = taskService.updateTask(definitionId, phaseId, taskUpdateDto); + TaskDto updatedTask = taskService.updateTask(definitionId, phaseId, taskId, taskUpdateDto); return new ResponseEntity<>(updatedTask, HttpStatus.OK); } diff --git a/src/main/java/com/example/demo/dto/TaskUpdateDto.java b/src/main/java/com/example/demo/dto/TaskUpdateDto.java index fb4c052d3d2f0f7720e3cea8c6f7876674a2856a..94690d578f257efadb8c37d58f39c5c386927cc0 100644 --- a/src/main/java/com/example/demo/dto/TaskUpdateDto.java +++ b/src/main/java/com/example/demo/dto/TaskUpdateDto.java @@ -8,10 +8,6 @@ import javax.validation.constraints.PositiveOrZero; public class TaskUpdateDto { - @ApiModelProperty(value = "Task ID", required = true, example = "1") - @NotNull(message = "Task ID must be specified") - private Long id; - @ApiModelProperty(value = "Short description of task", required = true, example = "Task title") @NotEmpty(message = "Task title must not be blank") private String title; @@ -33,14 +29,6 @@ public class TaskUpdateDto { @PositiveOrZero(message = "Limit of the number of provided incorrect flags must not be a negative number") private Integer incorrectFlagLimit; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - public String getTitle() { return title; } @@ -49,7 +37,6 @@ public class TaskUpdateDto { this.title = title; } - public String getContent() { return content; } @@ -85,8 +72,7 @@ public class TaskUpdateDto { @Override public String toString() { return "TaskUpdateDto{" + - "id=" + id + - ", title='" + title + '\'' + + "title='" + title + '\'' + ", content='" + content + '\'' + ", flag='" + flag + '\'' + ", solution='" + solution + '\'' + diff --git a/src/main/java/com/example/demo/service/TaskService.java b/src/main/java/com/example/demo/service/TaskService.java index 63c34c5ee4115cd3f5906a0ff6bb3c3736fb7663..d43baffba03e5739d8fc938d9d33a7c7bb86a09a 100644 --- a/src/main/java/com/example/demo/service/TaskService.java +++ b/src/main/java/com/example/demo/service/TaskService.java @@ -109,8 +109,9 @@ public class TaskService { return BeanMapper.INSTANCE.toDto(task); } - public TaskDto updateTask(Long trainingDefinitionId, Long phaseId, TaskUpdateDto taskUpdateDto) { + public TaskDto updateTask(Long trainingDefinitionId, Long phaseId, Long taskId, TaskUpdateDto taskUpdateDto) { Task taskUpdate = BeanMapper.INSTANCE.toEntity(taskUpdateDto); + taskUpdate.setId(taskId); Task persistedTask = taskRepository.findById(taskUpdate.getId()) .orElseThrow(() -> new RuntimeException("Task was not found"));