Search in sources :

Example 1 with TaskDto

use of com.viadee.sonarQuest.dtos.TaskDto in project sonarQuest by viadee.

the class TaskController method updateTask.

@CrossOrigin
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public TaskDto updateTask(@PathVariable(value = "id") final Long id, @RequestBody final TaskDto taskDto) {
    TaskDto resultTaskDto = null;
    final Task task = this.taskRepository.findById(id);
    if (task != null) {
        task.setTitle(taskDto.getTitle());
        task.setGold(taskDto.getGold());
        task.setXp(taskDto.getXp());
        this.taskRepository.save(task);
        resultTaskDto = toTaskDto(task);
    }
    if (task instanceof SpecialTask) {
        ((SpecialTask) task).setMessage(((SpecialTaskDto) taskDto).getMessage());
        this.taskRepository.save(task);
        resultTaskDto = toTaskDto(task);
    }
    return resultTaskDto;
}
Also used : SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) Task(com.viadee.sonarQuest.entities.Task) SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) SpecialTaskDto(com.viadee.sonarQuest.dtos.SpecialTaskDto) TaskDto(com.viadee.sonarQuest.dtos.TaskDto) TaskDto.toTaskDto(com.viadee.sonarQuest.dtos.TaskDto.toTaskDto) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TaskDto

use of com.viadee.sonarQuest.dtos.TaskDto in project sonarQuest by viadee.

the class TaskController method getAllTasksForWorld.

@CrossOrigin
@RequestMapping(value = "/world/{id}", method = RequestMethod.GET)
public List<List<TaskDto>> getAllTasksForWorld(@PathVariable(value = "id") final Long world_id) {
    World w = worldRepository.findOne(world_id);
    final List<List<TaskDto>> taskDtos = new ArrayList<>();
    List<TaskDto> specialTaskDtos = new ArrayList<>();
    List<TaskDto> standardTaskDtos = new ArrayList<>();
    specialTaskDtos = this.specialTaskRepository.findByWorld(w).stream().map(task -> toTaskDto(task)).collect(Collectors.toList());
    standardTaskDtos = this.standardTaskRepository.findByWorld(w).stream().map(task -> toTaskDto(task)).collect(Collectors.toList());
    taskDtos.add(specialTaskDtos);
    taskDtos.add(standardTaskDtos);
    return taskDtos;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) World(com.viadee.sonarQuest.entities.World) SpecialTaskDto(com.viadee.sonarQuest.dtos.SpecialTaskDto) TaskDto(com.viadee.sonarQuest.dtos.TaskDto) TaskDto.toTaskDto(com.viadee.sonarQuest.dtos.TaskDto.toTaskDto) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with TaskDto

use of com.viadee.sonarQuest.dtos.TaskDto in project sonarQuest by viadee.

the class TaskController method getFreeTasksForWorld.

@RequestMapping(value = "/getFreeForWorld/{worldId}", method = RequestMethod.GET)
public List<TaskDto> getFreeTasksForWorld(@PathVariable(value = "worldId") final Long worldId) {
    final World world = worldRepository.findOne(worldId);
    List<TaskDto> freeTasks = null;
    if (world != null) {
        // List<TaskDto> freeSpecialTasks = null;
        freeTasks = this.taskRepository.findByWorldAndStatus(world, TaskStates.CREATED).stream().map(task -> toTaskDto(task)).collect(Collectors.toList());
    /* 
             * @Florian - For what?
            freeSpecialTasks = this.specialTaskRepository.findByStatus(TaskStates.CREATED).stream().map(specialTask -> toTaskDto(specialTask)).collect(Collectors.toList());
            freeTasks.addAll(freeSpecialTasks);
             */
    }
    return freeTasks;
}
Also used : World(com.viadee.sonarQuest.entities.World) SpecialTaskDto(com.viadee.sonarQuest.dtos.SpecialTaskDto) TaskDto(com.viadee.sonarQuest.dtos.TaskDto) TaskDto.toTaskDto(com.viadee.sonarQuest.dtos.TaskDto.toTaskDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with TaskDto

use of com.viadee.sonarQuest.dtos.TaskDto in project sonarQuest by viadee.

the class TaskController method updateStandardTasksForWorld.

@CrossOrigin
@RequestMapping(value = "/updateStandardTasks/{worldId}", method = RequestMethod.GET)
public List<TaskDto> updateStandardTasksForWorld(@PathVariable(value = "worldId") final Long worldId) {
    final World world = worldRepository.findOne(worldId);
    List<TaskDto> taskDtos = null;
    if (world != null) {
        standardTaskService.updateStandardTasks(world);
        final List<Task> savedTasks = taskRepository.findAll();
        taskDtos = savedTasks.stream().map(task -> toTaskDto(task)).collect(Collectors.toList());
    }
    return taskDtos;
}
Also used : SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) Task(com.viadee.sonarQuest.entities.Task) World(com.viadee.sonarQuest.entities.World) SpecialTaskDto(com.viadee.sonarQuest.dtos.SpecialTaskDto) TaskDto(com.viadee.sonarQuest.dtos.TaskDto) TaskDto.toTaskDto(com.viadee.sonarQuest.dtos.TaskDto.toTaskDto) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SpecialTaskDto (com.viadee.sonarQuest.dtos.SpecialTaskDto)4 TaskDto (com.viadee.sonarQuest.dtos.TaskDto)4 TaskDto.toTaskDto (com.viadee.sonarQuest.dtos.TaskDto.toTaskDto)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 World (com.viadee.sonarQuest.entities.World)3 CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)3 SpecialTask (com.viadee.sonarQuest.entities.SpecialTask)2 Task (com.viadee.sonarQuest.entities.Task)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1