using API.Models; using API.Persistence.Repositories; using Microsoft.AspNetCore.Mvc; namespace API.Application.Users.Queries { public class QueryAllUsers { private readonly IUserRepository _repository; public QueryAllUsers(IUserRepository repository) { _repository = repository; } public async Task>> Handle() { List users = await _repository.QueryAllUsersAsync(); if (!users.Any()) { return new ConflictObjectResult(new { message = "No users found." }); } List userDTOs = users.Select(user => new UserDTO { Id = user.Id, Email = user.Email, Username = user.Username }).ToList(); return userDTOs; } } }