using Managing.Application.Abstractions; using Managing.Application.Abstractions.Services; using Managing.Application.ManageBot.Commands; using Managing.Domain.Bots; using Managing.Domain.Users; using MediatR; namespace Managing.Application.ManageBot { /// /// Handler for retrieving all agents and their strategies /// public class GetAllAgentsCommandHandler : IRequestHandler>> { private readonly IBotService _botService; private readonly IUserService _userService; public GetAllAgentsCommandHandler(IBotService botService, IUserService userService) { _botService = botService; _userService = userService; } public async Task>> Handle(GetAllAgentsCommand request, CancellationToken cancellationToken) { // Get all users var allUsers = await _userService.GetAllUsersAsync(); // Create result dictionary var result = new Dictionary>(); // For each user, get their bots foreach (var user in allUsers) { var userBots = await _botService.GetBotsByUser(user.Id); var botList = userBots.ToList(); result[user] = botList; } return result; } } }