update
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Commands.CreateOrUpdateConfiguration;
|
||||
|
||||
public record CreateOrUpdateConfigurationCommand : IRequest<Unit>
|
||||
{
|
||||
public string Key { get; init; } = string.Empty;
|
||||
public string Value { get; init; } = string.Empty;
|
||||
public string? Description { get; init; }
|
||||
public int Scope { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using BackOffice.BFF.Configuration.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Commands.CreateOrUpdateConfiguration;
|
||||
|
||||
public class CreateOrUpdateConfigurationCommandHandler : IRequestHandler<CreateOrUpdateConfigurationCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public CreateOrUpdateConfigurationCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(CreateOrUpdateConfigurationCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var grpcRequest = new CreateOrUpdateConfigurationRequest
|
||||
{
|
||||
Key = request.Key,
|
||||
Value = request.Value,
|
||||
Scope = request.Scope
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Description))
|
||||
{
|
||||
grpcRequest.Description = request.Description;
|
||||
}
|
||||
|
||||
await _context.Configurations.CreateOrUpdateConfigurationAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Commands.DeactivateConfiguration;
|
||||
|
||||
public record DeactivateConfigurationCommand : IRequest<Unit>
|
||||
{
|
||||
public string Key { get; init; } = string.Empty;
|
||||
public string? Reason { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using BackOffice.BFF.Configuration.Protobuf;
|
||||
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Commands.DeactivateConfiguration;
|
||||
|
||||
public class DeactivateConfigurationCommandHandler : IRequestHandler<DeactivateConfigurationCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public DeactivateConfigurationCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeactivateConfigurationCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var grpcRequest = new DeactivateConfigurationRequest
|
||||
{
|
||||
Key = request.Key
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Reason))
|
||||
{
|
||||
grpcRequest.Reason = request.Reason;
|
||||
}
|
||||
|
||||
await _context.Configurations.DeactivateConfigurationAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Queries.GetAllConfigurations;
|
||||
|
||||
public record GetAllConfigurationsQuery : IRequest<GetAllConfigurationsResponseDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// فیلتر بر اساس محدوده (System, Network, Club, Commission)
|
||||
/// </summary>
|
||||
public int? Scope { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// فقط تنظیمات فعال
|
||||
/// </summary>
|
||||
public bool? IsActive { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// شماره صفحه
|
||||
/// </summary>
|
||||
public int PageIndex { get; init; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// تعداد در صفحه
|
||||
/// </summary>
|
||||
public int PageSize { get; init; } = 20;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using BackOffice.BFF.Configuration.Protobuf;
|
||||
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Queries.GetAllConfigurations;
|
||||
|
||||
public class GetAllConfigurationsQueryHandler : IRequestHandler<GetAllConfigurationsQuery, GetAllConfigurationsResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetAllConfigurationsQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllConfigurationsResponseDto> Handle(GetAllConfigurationsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var grpcRequest = new GetAllConfigurationsRequest
|
||||
{
|
||||
PageIndex = request.PageIndex,
|
||||
PageSize = request.PageSize
|
||||
};
|
||||
|
||||
if (request.Scope.HasValue)
|
||||
{
|
||||
grpcRequest.Scope = request.Scope.Value;
|
||||
}
|
||||
|
||||
if (request.IsActive.HasValue)
|
||||
{
|
||||
grpcRequest.IsActive = request.IsActive.Value;
|
||||
}
|
||||
|
||||
var response = await _context.Configurations.GetAllConfigurationsAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
var result = new GetAllConfigurationsResponseDto
|
||||
{
|
||||
MetaData = new MetaDataDto
|
||||
{
|
||||
TotalCount = (int)(response.MetaData?.TotalCount ?? 0),
|
||||
PageSize = (int)(response.MetaData?.PageSize ?? request.PageSize),
|
||||
CurrentPage = (int)(response.MetaData?.CurrentPage ?? request.PageIndex),
|
||||
TotalPages = (int)(response.MetaData?.TotalPage ?? 0)
|
||||
},
|
||||
Models = response.Models.Select(m => new ConfigurationDto
|
||||
{
|
||||
Id = m.Id,
|
||||
Key = m.Key,
|
||||
Value = m.Value,
|
||||
Description = m.Description,
|
||||
Scope = m.Scope,
|
||||
ScopeDisplay = GetScopeDisplay(m.Scope),
|
||||
IsActive = m.IsActive,
|
||||
Created = m.Created?.ToDateTime() ?? DateTime.UtcNow
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetScopeDisplay(int scope)
|
||||
{
|
||||
return scope switch
|
||||
{
|
||||
0 => "سیستم",
|
||||
1 => "شبکه",
|
||||
2 => "باشگاه",
|
||||
3 => "کمیسیون",
|
||||
_ => "نامشخص"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Queries.GetAllConfigurations;
|
||||
|
||||
public record GetAllConfigurationsResponseDto
|
||||
{
|
||||
public MetaDataDto MetaData { get; init; } = new();
|
||||
public List<ConfigurationDto> Models { get; init; } = new();
|
||||
}
|
||||
|
||||
public record ConfigurationDto
|
||||
{
|
||||
public long Id { get; init; }
|
||||
public string Key { get; init; } = string.Empty;
|
||||
public string Value { get; init; } = string.Empty;
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public int Scope { get; init; }
|
||||
public string ScopeDisplay { get; init; } = string.Empty;
|
||||
public bool IsActive { get; init; }
|
||||
public DateTime Created { get; init; }
|
||||
}
|
||||
|
||||
public record MetaDataDto
|
||||
{
|
||||
public int TotalCount { get; init; }
|
||||
public int PageSize { get; init; }
|
||||
public int CurrentPage { get; init; }
|
||||
public int TotalPages { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user