-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathUserController.java
More file actions
55 lines (44 loc) · 1.73 KB
/
UserController.java
File metadata and controls
55 lines (44 loc) · 1.73 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
package com.accenture.codingtest.springbootcodingtest.controller;
import com.accenture.codingtest.springbootcodingtest.model.UserDto;
import com.accenture.codingtest.springbootcodingtest.service.UserService;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.UUID;
@RestController
@RequestMapping("/api/v1/users")
@RequiredArgsConstructor
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
@Secured("ROLE_ADMIN")
public class UserController {
private final UserService userService;
@GetMapping
public Collection<UserDto> findAll() {
return userService.findAll();
}
@GetMapping("/{id}")
public UserDto findById(@PathVariable("id") String id) {
return userService.findById(UUID.fromString(id));
}
@PostMapping("/")
public UserDto create(@RequestBody UserDto userDto) {
return userService.create(userDto);
}
@PutMapping("/{id}")
public UserDto update(@PathVariable("id") String id, @RequestBody UserDto userDto) {
return userService.update(UUID.fromString(id), userDto);
}
@PatchMapping("/{id}")
public UserDto updatePartially(@PathVariable("id") String id, @RequestBody UserDto userDto) {
return userService.updatePartially(UUID.fromString(id), userDto);
}
@DeleteMapping("/{id}")
public ResponseEntity deleteById(@PathVariable("id") String id) {
userService.deleteById(UUID.fromString(id));
return ResponseEntity.ok().build();
}
}