-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathTaskController.java
70 lines (59 loc) · 2.51 KB
/
TaskController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.accenture.codingtest.springbootcodingtest.controller;
import java.util.List;
import com.accenture.codingtest.springbootcodingtest.model.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.accenture.codingtest.springbootcodingtest.entity.Task;
import com.accenture.codingtest.springbootcodingtest.service.TaskService;
@RestController
@RequestMapping("/api")
public class TaskController {
@Autowired
private TaskService taskService;
@GetMapping("/v1/tasks")
public ResponseEntity<List<Task>> getAllTasks() {
return taskService.getAllTasks();
}
@PostMapping("/v1/tasks/{role}")
public ResponseEntity<Task> saveTask(@RequestBody Task task, @PathVariable("role") String role) {
ResponseEntity<Task> response = null;
if(Role.PRODUCT_OWNER.toString().equalsIgnoreCase(role)) {
response = taskService.saveTask(task);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}
@GetMapping("/v1/tasks/{task_id}")
public ResponseEntity<Task> getTaskById(@PathVariable("task_id") String task_id) {
return taskService.getTaskById(task_id);
}
@PatchMapping("/v1/tasks/{role}")
public ResponseEntity<Task> updateTask(@RequestBody Task task,
@PathVariable("userId") String userId,
@PathVariable("role") String role) {
ResponseEntity<Task> response = null;
if(Role.PRODUCT_OWNER.toString().equalsIgnoreCase(role)) {
response = taskService.updateTask(task, userId);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}
@PutMapping("/v1/tasks/{role}")
public ResponseEntity<Task> updateTask(@RequestBody Task task, @PathVariable("role") String role) {
ResponseEntity<Task> response = null;
if(Role.PRODUCT_OWNER.toString().equalsIgnoreCase(role)) {
response = taskService.updateTask(task);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}
@DeleteMapping("/v1/tasks/{task_id}")
public ResponseEntity<Void> deleteTaskById(@PathVariable("task_id") String task_id) {
return taskService.deleteTask(task_id);
}
}