Created
March 29, 2021 04:41
-
-
Save mehmetcemyucel/e173101affb6642f879dd9c7b7b0369a to your computer and use it in GitHub Desktop.
spring-native-example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.cem.springnativeexample.controller; | |
| import com.cem.springnativeexample.controller.model.User; | |
| import com.cem.springnativeexample.service.UserService; | |
| import com.sun.istack.NotNull; | |
| import org.springframework.security.access.prepost.PreAuthorize; | |
| import org.springframework.web.bind.annotation.*; | |
| import java.util.Collection; | |
| import java.util.Optional; | |
| @RestController | |
| @RequestMapping("/users") | |
| public class UserController { | |
| private final UserService userService; | |
| public UserController(UserService userService) { | |
| this.userService = userService; | |
| } | |
| @GetMapping | |
| // @PreAuthorize("hasRole('ROLE_VIEWER')") | |
| public Collection<User> getUsers() { | |
| return userService.getUsers(); | |
| } | |
| @GetMapping("/{id}") | |
| // @PreAuthorize("hasRole('ROLE_VIEWER')") | |
| public Optional<User> getUser(@PathVariable @NotNull Long id) { | |
| return userService.getUser(id); | |
| } | |
| @PostMapping | |
| // @PreAuthorize("hasRole('ROLE_EDITOR')") | |
| public void createUser(@RequestBody User user) { | |
| userService.createUser(user); | |
| } | |
| @DeleteMapping("{id}") | |
| // @PreAuthorize("hasRole('ROLE_EDITOR')") | |
| public void deleteUser(@PathVariable @NotNull Long id) { | |
| userService.deleteUser(id); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment