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

Change REST API retrieving tasks according to the new design

Related to #10
parent 806d0e64
No related branches found
No related tags found
No related merge requests found
...@@ -40,31 +40,31 @@ public class TaskController { ...@@ -40,31 +40,31 @@ public class TaskController {
this.taskService = taskService; this.taskService = taskService;
} }
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) // @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Create a new task") // @ApiOperation(value = "Create a new task")
@ApiResponses(value = {@ApiResponse(code = 200, message = "New game level created"), // @ApiResponses(value = {@ApiResponse(code = 200, message = "New game level created"),
@ApiResponse(code = 500, message = "Unexpected application error")}) // @ApiResponse(code = 500, message = "Unexpected application error")})
public TaskDto createGameLevel(@ApiParam(value = "Game level", required = true) @RequestBody(required = true) // public TaskDto createGameLevel(@ApiParam(value = "Game level", required = true) @RequestBody(required = true)
TaskCreateDto taskCreateDto) { // TaskCreateDto taskCreateDto) {
return taskService.createTask(taskCreateDto); // return taskService.createTask(taskCreateDto);
} // }
//
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) // @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Return game levels") // @ApiOperation(value = "Return game levels")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Return game levels"), // @ApiResponses(value = {@ApiResponse(code = 200, message = "Return game levels"),
@ApiResponse(code = 500, message = "Unexpected application error")}) // @ApiResponse(code = 500, message = "Unexpected application error")})
public List<TaskDto> findGameLevels() { // public List<TaskDto> findGameLevels() {
return taskService.findAllTasks(); // return taskService.findAllTasks();
} // }
//
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) // @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get game level detail") // @ApiOperation(value = "Get game level detail")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Game level detail"), // @ApiResponses(value = {@ApiResponse(code = 200, message = "Game level detail"),
@ApiResponse(code = 500, message = "Unexpected application error")}) // @ApiResponse(code = 500, message = "Unexpected application error")})
public TaskDto getGameLevel( // public TaskDto getGameLevel(
@ApiParam(value = "Game Level ID", required = true) @PathVariable("id") final Long id) { // @ApiParam(value = "Game Level ID", required = true) @PathVariable("id") final Long id) {
return taskService.getTask(id); // return taskService.getTask(id);
} // }
// TODO this will be probably removed. This operation is implemented in AdaptiveTrainingDefinitionsRestController // TODO this will be probably removed. This operation is implemented in AdaptiveTrainingDefinitionsRestController
// @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) // @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
...@@ -78,11 +78,11 @@ public class TaskController { ...@@ -78,11 +78,11 @@ public class TaskController {
// return gameLevelService.updateGameLevel(id, gameLevelUpdateDto); // return gameLevelService.updateGameLevel(id, gameLevelUpdateDto);
// } // }
@DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) // @DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Remove game level") // @ApiOperation(value = "Remove game level")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Game level removed"), // @ApiResponses(value = {@ApiResponse(code = 200, message = "Game level removed"),
@ApiResponse(code = 500, message = "Unexpected application error")}) // @ApiResponse(code = 500, message = "Unexpected application error")})
public void removeGameLevel(@ApiParam(value = "Game Level ID", required = true) @PathVariable("id") final Long id) { // public void removeGameLevel(@ApiParam(value = "Game Level ID", required = true) @PathVariable("id") final Long id) {
taskService.removeTaskLevel(id); // taskService.removeTaskLevel(id);
} // }
} }
...@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -77,4 +78,28 @@ public class TasksController { ...@@ -77,4 +78,28 @@ public class TasksController {
return new ResponseEntity<>(createdTask, HttpStatus.CREATED); return new ResponseEntity<>(createdTask, HttpStatus.CREATED);
} }
@ApiOperation(httpMethod = "GET",
value = "Get tasks",
notes = "Get tasks detail associated with the specified game phase",
response = TaskDto.class,
nickname = "getTask",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Task returned"),
@ApiResponse(code = 500, message = "Unexpected application error")
})
@GetMapping(path = "/{taskId}")
public ResponseEntity<TaskDto> getTask(
@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) {
TaskDto createdTask = taskService.getTask(definitionId, phaseId, taskId);
return new ResponseEntity<>(createdTask, HttpStatus.CREATED);
}
} }
...@@ -95,15 +95,14 @@ public class TaskService { ...@@ -95,15 +95,14 @@ public class TaskService {
return result; return result;
} }
public TaskDto getTask(Long id) { public TaskDto getTask(Long trainingDefinitionId, Long phaseId, Long taskId) {
Optional<Task> task = taskRepository.findById(id); Task task = taskRepository.findById(taskId)
.orElseThrow(() -> new RuntimeException("Task was not found"));
// TODO throw proper exception once kypo2-training is migrated
if (task.isEmpty()) { // TODO add check to trainingDefinitionId and phaseId (field structure will be probably changed)
LOG.error("No task found with ID {}.", id);
return new TaskDto();
}
return BeanMapper.INSTANCE.toDto(task.get()); return BeanMapper.INSTANCE.toDto(task);
} }
public TaskDto updateTask(Task taskUpdate) { public TaskDto updateTask(Task taskUpdate) {
......
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