-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathCodingTestController.java
More file actions
213 lines (181 loc) · 6.19 KB
/
CodingTestController.java
File metadata and controls
213 lines (181 loc) · 6.19 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package com.accenture.codingtest.springbootcodingtest.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.accenture.codingtest.springbootcodingtest.entity.Project;
import com.accenture.codingtest.springbootcodingtest.entity.Task;
import com.accenture.codingtest.springbootcodingtest.entity.User;
import com.accenture.codingtest.springbootcodingtest.service.CodingTestService;
@RestController
@RequestMapping(path = "api/v1")
public class CodingTestController {
@Autowired
CodingTestService testService;
enum Role {
ADMIN, PRODUCT_OWNER
}
enum Status {
NOT_STARTED, IN_PROGRESS, READY_FOR_TEST, COMPLETED
}
@GetMapping("/users/{role}")
private List<User> getUsers(@PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
return testService.getUsers();
} else {
return null;
}
}
@PostMapping("/users/{role}")
private String saveUser(@RequestBody User user, @PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
testService.saveOrUpdate(user);
return user.getId();
} else {
return null;
}
}
@PutMapping("/users/{id}/{role}")
private String updateUser(@RequestBody User user, @PathVariable("id") String id,
@PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
testService.updateById(user, id);
return user.getId();
} else {
return null;
}
}
@PatchMapping("/users/{id}/{role}")
private String patchUser(@RequestBody User user, @PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
testService.updateById(user, id);
return user.getId();
} else {
return null;
}
}
@GetMapping("/user/{id}/{role}")
private User getUserById(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
return testService.getUserById(id);
}else {
return null;
}
}
@DeleteMapping("/user/{id}/{role}")
private void deleteUser(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.ADMIN.name().equalsIgnoreCase(role)) {
testService.delete(id);
}
}
@GetMapping("/projects/{role}")
private List<Project> getProjects(@PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
return testService.getProjects();
}else {
return null;
}
}
@PostMapping("/projects/{role}")
private String saveProject(@RequestBody Project project, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.saveOrUpdate(project);
return project.getId();
}else {
return null;
}
}
@PutMapping("/projects/{id}/{role}")
private String updateUser(@RequestBody Project project, @PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.updateById(project, id);
return project.getId();
}else {
return null;
}
}
@PatchMapping("/projects/{id}/{role}")
private String patchUser(@RequestBody Project project, @PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.updateById(project, id);
return project.getId();
}else {
return null;
}
}
@GetMapping("/project/{id}/{role}")
private Project getProjectById(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
return testService.getProjectById(id);
}else {
return null;
}
}
@DeleteMapping("/project/{id}/{role}")
private void deleteProject(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.delete(id);
}
}
@GetMapping("/tasks/{role}")
private List<Task> getTasks(@PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
return testService.getTasks();
}else {
return null;
}
}
@GetMapping("/tasks/{role}/{userId}")
private List<Task> getTasksByUserId(@PathVariable("role") String role,@PathVariable("userId") String userId) {
return testService.getTasksByUserId(userId);
}
@PostMapping("/tasks/{role}")
private String saveTask(@RequestBody Task task, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.saveOrUpdate(task);
return task.getId();
}else {
return null;
}
}
@PutMapping("/tasks/{id}/{role}")
private String updateTask(@RequestBody Task task, @PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.updateById(task, id);
return task.getId();
}else {
return null;
}
}
@PatchMapping("/tasks/{id}/{role}/{userId}")
private String patchTask(@RequestBody Task task, @PathVariable("id") String id, @PathVariable("role") String role,@PathVariable("userId") String userId) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.updateById(task, id);
return task.getId();
}else {
testService.updateById(task, id,userId);
return task.getId();
}
}
@GetMapping("/task/{id}/{role}")
private Task getTaskById(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
return testService.getTaskById(id);
}else {
return null;
}
}
@DeleteMapping("/task/{id}/{role}")
private void deleteTask(@PathVariable("id") String id, @PathVariable("role") String role) {
if (Role.PRODUCT_OWNER.name().equalsIgnoreCase(role)) {
testService.delete(id);
}
}
}