-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from aceton41k/fixed_async
async task fixed
- Loading branch information
Showing
6 changed files
with
61 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 27 additions & 13 deletions
40
src/main/java/com/github/aceton41k/controller/TaskController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
package com.github.aceton41k.controller; | ||
|
||
import com.github.aceton41k.dto.Task; | ||
import com.github.aceton41k.dto.TaskDto; | ||
import com.github.aceton41k.service.TaskService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
||
import java.util.List; | ||
import java.net.URI; | ||
|
||
@RestController | ||
@RequestMapping("/api/task") | ||
@RequestMapping("/api/tasks") | ||
public class TaskController { | ||
|
||
@Autowired | ||
private TaskService taskService; | ||
|
||
@GetMapping("/create") | ||
public String createTask(@RequestParam Integer duration) { | ||
Long taskId = taskService.createTask(duration); | ||
return "Task created with ID: " + taskId; | ||
@PostMapping | ||
public ResponseEntity<TaskDto> createTask(@RequestParam @Nullable Integer duration) { | ||
TaskDto task = taskService.createTask(duration); | ||
URI location = ServletUriComponentsBuilder.fromCurrentRequest() | ||
.path("/{id}") | ||
.buildAndExpand(task.getId()) | ||
.toUri(); | ||
return ResponseEntity.created(location).body(task); | ||
} | ||
|
||
@GetMapping("/status/{id}") | ||
public Task getTaskStatus(@PathVariable Long id) { | ||
return taskService.getTaskStatus(id); | ||
@GetMapping("/{id}") | ||
public ResponseEntity<TaskDto> getTask(@PathVariable Long id) { | ||
TaskDto task = taskService.getTask(id); | ||
return ResponseEntity.ok(task); | ||
} | ||
|
||
@GetMapping("/status") | ||
public List<Task> getTaskStatus() { | ||
return taskService.getAllTasks(); | ||
@GetMapping | ||
public ResponseEntity<Page<TaskDto>> getAllTasks(@RequestParam(value = "page", defaultValue = "0") Integer page, | ||
@RequestParam(value = "size", defaultValue = "10") Integer size) { | ||
Pageable pageable = PageRequest.of(page, size); | ||
Page<TaskDto> tasks = taskService.getAllTasks(pageable); | ||
return ResponseEntity.ok(tasks); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters