-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathProjectController.java
More file actions
53 lines (42 loc) · 1.75 KB
/
ProjectController.java
File metadata and controls
53 lines (42 loc) · 1.75 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 com.accenture.codingtest.springbootcodingtest.model.ProjectDto;
import com.accenture.codingtest.springbootcodingtest.service.ProjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.UUID;
@RestController
@RequestMapping("/api/v1/projects")
@RequiredArgsConstructor
public class ProjectController {
private final ProjectService projectService;
@GetMapping
public Collection<ProjectDto> findAll() {
return projectService.findAll();
}
@GetMapping("/{id}")
public ProjectDto findById(@PathVariable("id") String id) {
return projectService.findById(UUID.fromString(id));
}
@PostMapping("/")
@PreAuthorize("hasAuthority('ROLE_PRODUCT_OWNER')")
public ProjectDto create(@RequestBody ProjectDto projectDto) {
return projectService.create(projectDto);
}
@PutMapping("/{id}")
public ProjectDto update(@PathVariable("id") String id, @RequestBody ProjectDto projectDto) {
return projectService.update(UUID.fromString(id), projectDto);
}
@PatchMapping("/{id}")
public ProjectDto updatePartially(@PathVariable("id") String id, @RequestBody ProjectDto projectDto) {
return projectService.updatePartially(UUID.fromString(id), projectDto);
}
@DeleteMapping("/{id}")
public ResponseEntity deleteById(@PathVariable("id") String id) {
projectService.deleteById(UUID.fromString(id));
return ResponseEntity.ok().build();
}
}