Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get All User List #40

Open
shangariV opened this issue Jul 27, 2023 · 2 comments
Open

Get All User List #40

shangariV opened this issue Jul 27, 2023 · 2 comments

Comments

@shangariV
Copy link

Hello Team,

This project has been beneficial for authentication compared to other open-source options. However, I'm facing an issue retrieving the user list as I get an access denied exception. I've tried accessing it with and without passing authentication, but the problem persists. Can you please guide me on how to resolve this? Thank you!

@Neelesh-Janga
Copy link

Neelesh-Janga commented Jul 27, 2023

Write a Jpa query inside UserRepository and make the return type as List. In controller class, write return response entity of type list of Users as new ResponseEntity<List<User>>(users, HttpStatus.OK). Feel free to make a thread of it as it benefits others and me as well to discuss and learn.

@shangariV
Copy link
Author

Thanks for the response. Yes Got it.

  public List<UserResponse> getAllUsers() {
        var userList = repository.findAll();
        List<UserResponse> userResponses = new ArrayList<>();
        for (User user : userList) {
            UserResponse userResponse = UserResponse.builder()
                    .firstName(user.getFirstname())
                    .email(user.getEmail())
                    .lastName(user.getLastname())
                    .build();
            userResponses.add(userResponse);
        }
        return userResponses;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants