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