Skip to content
Snippets Groups Projects
Commit c2d287a6 authored by Jan Tymel's avatar Jan Tymel
Browse files

Move task ID to URI path instead of body when task is updated

Related to #3
parent 99f45390
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......
......@@ -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 + '\'' +
......
......@@ -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"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment