2024-08-15 14:21:17 +01:00
|
|
|
|
using AuthorizationService.Models;
|
|
|
|
|
using AuthorizationService.Persistence.Repositories;
|
2024-08-13 12:29:01 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
2024-08-15 14:21:17 +01:00
|
|
|
|
namespace AuthorizationService.Application.Users.Queries
|
2024-08-13 12:29:01 +01:00
|
|
|
|
{
|
|
|
|
|
public class QueryAllUsers
|
|
|
|
|
{
|
|
|
|
|
private readonly IUserRepository _repository;
|
|
|
|
|
|
|
|
|
|
public QueryAllUsers(IUserRepository repository)
|
|
|
|
|
{
|
|
|
|
|
_repository = repository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<ActionResult<List<UserDTO>>> Handle()
|
|
|
|
|
{
|
|
|
|
|
List<User> users = await _repository.QueryAllUsersAsync();
|
|
|
|
|
|
|
|
|
|
if (!users.Any())
|
|
|
|
|
{
|
|
|
|
|
return new ConflictObjectResult(new { message = "No users found." });
|
|
|
|
|
}
|
|
|
|
|
List<UserDTO> userDTOs = users.Select(user => new UserDTO
|
|
|
|
|
{
|
|
|
|
|
Id = user.Id,
|
|
|
|
|
Email = user.Email,
|
|
|
|
|
Username = user.Username
|
|
|
|
|
}).ToList();
|
|
|
|
|
return userDTOs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|