34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using Heimdall.Application.Common;
|
|||
|
|
using MediatR;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
|
||
|
|
namespace Heimdall.Application.Settings.Queries.GetEffectiveAgentConfig;
|
||
|
|
|
||
|
|
public record GetEffectiveAgentConfigQuery(Guid AgentId) : IRequest<ServiceResult<Dictionary<string, string>>>;
|
||
|
|
|
||
|
|
public class GetEffectiveAgentConfigQueryHandler
|
||
|
|
: IRequestHandler<GetEffectiveAgentConfigQuery, ServiceResult<Dictionary<string, string>>>
|
||
|
|
{
|
||
|
|
private readonly IApplicationDbContext _db;
|
||
|
|
|
||
|
|
public GetEffectiveAgentConfigQueryHandler(IApplicationDbContext db) => _db = db;
|
||
|
|
|
||
|
|
public async Task<ServiceResult<Dictionary<string, string>>> Handle(
|
||
|
|
GetEffectiveAgentConfigQuery request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
var appSettings = await _db.AppSettings.ToListAsync(ct);
|
||
|
|
var config = new Dictionary<string, string>(StringComparer.Ordinal);
|
||
|
|
|
||
|
|
foreach (var s in appSettings)
|
||
|
|
config[s.Key] = s.Value;
|
||
|
|
|
||
|
|
var agentSettings = await _db.AgentSettings
|
||
|
|
.Where(s => s.AgentId == request.AgentId)
|
||
|
|
.ToListAsync(ct);
|
||
|
|
|
||
|
|
foreach (var s in agentSettings)
|
||
|
|
config[s.Key] = s.Value;
|
||
|
|
|
||
|
|
return ServiceResult<Dictionary<string, string>>.Success(config);
|
||
|
|
}
|
||
|
|
}
|