diff --git a/src/main/java/com/example/demo/controller/TaskController.java b/src/main/java/com/example/demo/controller/TaskController.java index 641e3db34702d951c6c7a9833da185ed4381f4c4..40549debf5212fcf47021ebc3f9dc8708f1a447c 100644 --- a/src/main/java/com/example/demo/controller/TaskController.java +++ b/src/main/java/com/example/demo/controller/TaskController.java @@ -40,31 +40,31 @@ public class TaskController { this.taskService = taskService; } - @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation(value = "Create a new task") - @ApiResponses(value = {@ApiResponse(code = 200, message = "New game level created"), - @ApiResponse(code = 500, message = "Unexpected application error")}) - public TaskDto createGameLevel(@ApiParam(value = "Game level", required = true) @RequestBody(required = true) - TaskCreateDto taskCreateDto) { - return taskService.createTask(taskCreateDto); - } - - @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation(value = "Return game levels") - @ApiResponses(value = {@ApiResponse(code = 200, message = "Return game levels"), - @ApiResponse(code = 500, message = "Unexpected application error")}) - public List<TaskDto> findGameLevels() { - return taskService.findAllTasks(); - } - - @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation(value = "Get game level detail") - @ApiResponses(value = {@ApiResponse(code = 200, message = "Game level detail"), - @ApiResponse(code = 500, message = "Unexpected application error")}) - public TaskDto getGameLevel( - @ApiParam(value = "Game Level ID", required = true) @PathVariable("id") final Long id) { - return taskService.getTask(id); - } +// @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) +// @ApiOperation(value = "Create a new task") +// @ApiResponses(value = {@ApiResponse(code = 200, message = "New game level created"), +// @ApiResponse(code = 500, message = "Unexpected application error")}) +// public TaskDto createGameLevel(@ApiParam(value = "Game level", required = true) @RequestBody(required = true) +// TaskCreateDto taskCreateDto) { +// return taskService.createTask(taskCreateDto); +// } +// +// @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) +// @ApiOperation(value = "Return game levels") +// @ApiResponses(value = {@ApiResponse(code = 200, message = "Return game levels"), +// @ApiResponse(code = 500, message = "Unexpected application error")}) +// public List<TaskDto> findGameLevels() { +// return taskService.findAllTasks(); +// } +// +// @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) +// @ApiOperation(value = "Get game level detail") +// @ApiResponses(value = {@ApiResponse(code = 200, message = "Game level detail"), +// @ApiResponse(code = 500, message = "Unexpected application error")}) +// public TaskDto getGameLevel( +// @ApiParam(value = "Game Level ID", required = true) @PathVariable("id") final Long id) { +// return taskService.getTask(id); +// } // TODO this will be probably removed. This operation is implemented in AdaptiveTrainingDefinitionsRestController // @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @@ -78,11 +78,11 @@ public class TaskController { // return gameLevelService.updateGameLevel(id, gameLevelUpdateDto); // } - @DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation(value = "Remove game level") - @ApiResponses(value = {@ApiResponse(code = 200, message = "Game level removed"), - @ApiResponse(code = 500, message = "Unexpected application error")}) - public void removeGameLevel(@ApiParam(value = "Game Level ID", required = true) @PathVariable("id") final Long id) { - taskService.removeTaskLevel(id); - } +// @DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) +// @ApiOperation(value = "Remove game level") +// @ApiResponses(value = {@ApiResponse(code = 200, message = "Game level removed"), +// @ApiResponse(code = 500, message = "Unexpected application error")}) +// public void removeGameLevel(@ApiParam(value = "Game Level ID", required = true) @PathVariable("id") final Long id) { +// taskService.removeTaskLevel(id); +// } } diff --git a/src/main/java/com/example/demo/controller/TasksController.java b/src/main/java/com/example/demo/controller/TasksController.java index bd2bf827f4d5096c410f68a11af2fa8ec36dceee..a5fc6b08f9a50caaec63a7189dfe4e91e83906e5 100644 --- a/src/main/java/com/example/demo/controller/TasksController.java +++ b/src/main/java/com/example/demo/controller/TasksController.java @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; 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.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -77,4 +78,28 @@ public class TasksController { 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); + } } diff --git a/src/main/java/com/example/demo/service/TaskService.java b/src/main/java/com/example/demo/service/TaskService.java index 51b87b64774d6ddd07e50559f9699a8bfdaf3444..be7c887c33618887a215d56a5fe46c74a00670a8 100644 --- a/src/main/java/com/example/demo/service/TaskService.java +++ b/src/main/java/com/example/demo/service/TaskService.java @@ -95,15 +95,14 @@ public class TaskService { return result; } - public TaskDto getTask(Long id) { - Optional<Task> task = taskRepository.findById(id); + public TaskDto getTask(Long trainingDefinitionId, Long phaseId, Long taskId) { + Task task = taskRepository.findById(taskId) + .orElseThrow(() -> new RuntimeException("Task was not found")); + // TODO throw proper exception once kypo2-training is migrated - if (task.isEmpty()) { - LOG.error("No task found with ID {}.", id); - return new TaskDto(); - } + // TODO add check to trainingDefinitionId and phaseId (field structure will be probably changed) - return BeanMapper.INSTANCE.toDto(task.get()); + return BeanMapper.INSTANCE.toDto(task); } public TaskDto updateTask(Task taskUpdate) {