Created
February 6, 2023 10:00
-
-
Save KupchenkoArtur/b64a5ed936879a764c9f95cc459fbd22 to your computer and use it in GitHub Desktop.
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 ru.kata.spring.boot_security.demo.controllers; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.HttpHeaders; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.*; | |
import ru.kata.spring.boot_security.demo.entity.User; | |
import ru.kata.spring.boot_security.demo.service.RoleService; | |
import ru.kata.spring.boot_security.demo.service.UserService; | |
import java.util.List; | |
@RestController | |
@RequestMapping("/api") | |
public class RestAdminController { | |
private final UserService userService; | |
private final RoleService roleService; | |
@Autowired | |
public RestAdminController(UserService userService, RoleService roleService) { | |
this.userService = userService; | |
this.roleService = roleService; | |
} | |
@GetMapping | |
public ResponseEntity<List<User>> getAllUsers() { | |
List<User> users = userService.getAllUsers(); | |
if (users.isEmpty()) { | |
return new ResponseEntity<>(HttpStatus.NOT_FOUND); | |
} | |
return new ResponseEntity<>(users, HttpStatus.OK); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment