-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathProjectController.java
More file actions
53 lines (43 loc) · 1.9 KB
/
ProjectController.java
File metadata and controls
53 lines (43 loc) · 1.9 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
package com.accenture.codingtest.springbootcodingtest.controller;
import java.util.List;
import com.accenture.codingtest.springbootcodingtest.entity.Project;
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.Project;
import com.accenture.codingtest.springbootcodingtest.service.ProjectService;
@RestController
@RequestMapping("/api")
public class ProjectController {
@Autowired
private ProjectService projectService;
@GetMapping("/v1/projects")
public ResponseEntity<List<Project>> getAllProjects() {
return projectService.getAllProjects();
}
@PostMapping("/v1/projects/{role}")
public ResponseEntity<Project> saveProject(@RequestBody Project project,
@PathVariable("role") String role) {
ResponseEntity<Project> response;
if(Role.ADMIN.toString().equalsIgnoreCase(role)) {
response = projectService.saveProject(project);
} else {
response = new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
return response;
}
@GetMapping("/v1/projects/{project_id}")
public ResponseEntity<Project> getProjectById(@PathVariable("project_id") String project_id) {
return projectService.getProjectById(project_id);
}
@PutMapping("/v1/projects")
public ResponseEntity<Project> updateProject(@RequestBody Project project) {
return projectService.updateProject(project);
}
@DeleteMapping("/v1/projects/{project_id}")
public ResponseEntity<Void> deleteProjectById(@PathVariable("project_id") String project_id) {
return projectService.deleteProject(project_id);
}
}