add simple endpoint for users
This commit is contained in:
@@ -16,6 +16,7 @@ services:
|
||||
|
||||
app:
|
||||
image: popovtsev/ncp
|
||||
# build: .
|
||||
container_name: no_copy_app
|
||||
environment:
|
||||
POSTGRES_DB: no_copy_
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package ru.soune.no_copy.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class UserDTO {
|
||||
private String fullName;
|
||||
private String email;
|
||||
private boolean isActive;
|
||||
}
|
||||
@@ -53,6 +53,6 @@ public class User {
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "is_active")
|
||||
private Boolean isActive;
|
||||
private Boolean isActive = true;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user