29 lines
890 B
Java
29 lines
890 B
Java
package ru.soune.no_copy.controller;
|
|||
|
|
|
||
|
|
import lombok.RequiredArgsConstructor;
|
||
|
|
import org.springframework.http.ResponseEntity;
|
||
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RestController;
|
||
|
|
import ru.soune.no_copy.dto.UserDTO;
|
||
|
|
import ru.soune.no_copy.repository.UserRepository;
|
||
|
|
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/api/user")
|
||
|
|
@RequiredArgsConstructor
|
||
|
|
public class UserController {
|
||
|
|
|
||
|
|
private final UserRepository userRepository;
|
||
|
|
|
||
|
|
@GetMapping("/all")
|
||
|
|
public ResponseEntity<List<UserDTO>> getAllUsers() {
|
||
|
|
List<UserDTO> allUsers = userRepository.findAll().stream()
|
||
|
|
.map(u -> new UserDTO(u.getFirstName(), u.getEmail(), u.getIsActive()))
|
||
|
|
.toList();
|
||
|
|
|
||
|
|
return ResponseEntity.ok(allUsers);
|
||
|
|
}
|
||
|
|
}
|