Fix update AgentName
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Core;
|
||||
using Managing.Domain.Statistics;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Managing.Application.Agents;
|
||||
@@ -9,17 +11,20 @@ public class AgentService : IAgentService
|
||||
{
|
||||
private readonly IAgentBalanceRepository _agentBalanceRepository;
|
||||
private readonly IAgentSummaryRepository _agentSummaryRepository;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly ILogger<AgentService> _logger;
|
||||
|
||||
public AgentService(
|
||||
IAgentBalanceRepository agentBalanceRepository,
|
||||
IAgentSummaryRepository agentSummaryRepository,
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
ICacheService cacheService,
|
||||
ILogger<AgentService> logger)
|
||||
{
|
||||
_agentBalanceRepository = agentBalanceRepository;
|
||||
_agentSummaryRepository = agentSummaryRepository;
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
_cacheService = cacheService;
|
||||
_logger = logger;
|
||||
}
|
||||
@@ -96,6 +101,11 @@ public class AgentService : IAgentService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(agentSummary.AgentName))
|
||||
{
|
||||
agentSummary.AgentName = await ServiceScopeHelpers.WithScopedService<IUserService, string>(_serviceScopeFactory,
|
||||
async (userService) => (await userService.GetUserByIdAsync(agentSummary.UserId)).AgentName);
|
||||
}
|
||||
// Use the injected AgentSummaryRepository to save or update
|
||||
await _agentSummaryRepository.SaveOrUpdateAsync(agentSummary);
|
||||
|
||||
@@ -120,4 +130,19 @@ public class AgentService : IAgentService
|
||||
var agentSummaries = await _agentSummaryRepository.GetAllAgentWithRunningBots();
|
||||
return agentSummaries.Select(a => a.AgentName);
|
||||
}
|
||||
|
||||
public async Task UpdateAgentSummaryNameAsync(int userId, string agentName)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _agentSummaryRepository.UpdateAgentNameAsync(userId, agentName);
|
||||
|
||||
_logger.LogInformation("Agent name updated for user {UserId} to {AgentName}", userId, agentName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating agent name for user {UserId} to {AgentName}", userId, agentName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user