Skip to content

Instantly share code, notes, and snippets.

@KupchenkoArtur
Created February 6, 2023 10:00
Show Gist options
  • Save KupchenkoArtur/b64a5ed936879a764c9f95cc459fbd22 to your computer and use it in GitHub Desktop.
Save KupchenkoArtur/b64a5ed936879a764c9f95cc459fbd22 to your computer and use it in GitHub Desktop.
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