feat: add Configuration gRPC service and queries for club settings and features
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
namespace FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubConfiguration;
|
||||
|
||||
/// <summary>
|
||||
/// دریافت تنظیمات باشگاه مشتریان
|
||||
/// </summary>
|
||||
public record GetClubConfigurationQuery : IRequest<GetClubConfigurationResponseDto>;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Configuration;
|
||||
|
||||
namespace FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubConfiguration;
|
||||
|
||||
/// <summary>
|
||||
/// هندلر دریافت تنظیمات باشگاه مشتریان از CMS
|
||||
/// </summary>
|
||||
public class GetClubConfigurationQueryHandler : IRequestHandler<GetClubConfigurationQuery, GetClubConfigurationResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetClubConfigurationQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetClubConfigurationResponseDto> Handle(GetClubConfigurationQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// دریافت مبلغ فعالسازی از CMS
|
||||
var activationFeeRequest = new GetConfigurationByKeyRequest
|
||||
{
|
||||
Scope = 2, // ConfigurationScope.Club
|
||||
Key = "Club.ActivationFee"
|
||||
};
|
||||
|
||||
var giftValueRequest = new GetConfigurationByKeyRequest
|
||||
{
|
||||
Scope = 2, // ConfigurationScope.Club
|
||||
Key = "Club.MembershipGiftValue"
|
||||
};
|
||||
|
||||
var activationFeeResponse = await _context.Configuration.GetConfigurationByKeyAsync(activationFeeRequest, cancellationToken: cancellationToken);
|
||||
var giftValueResponse = await _context.Configuration.GetConfigurationByKeyAsync(giftValueRequest, cancellationToken: cancellationToken);
|
||||
|
||||
var response = new GetClubConfigurationResponseDto
|
||||
{
|
||||
ActivationFee = long.TryParse(activationFeeResponse?.Value, out var fee) ? fee : 25000000,
|
||||
MembershipGiftValue = long.TryParse(giftValueResponse?.Value, out var gift) ? gift : 25200000
|
||||
};
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
namespace FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubConfiguration;
|
||||
|
||||
/// <summary>
|
||||
/// پاسخ تنظیمات باشگاه مشتریان
|
||||
/// </summary>
|
||||
public class GetClubConfigurationResponseDto
|
||||
{
|
||||
/// <summary>
|
||||
/// هزینه فعالسازی عضویت باشگاه (ریال)
|
||||
/// </summary>
|
||||
public long ActivationFee { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// مبلغ هدیه حق عضویت باشگاه (ریال)
|
||||
/// </summary>
|
||||
public long MembershipGiftValue { get; set; }
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
namespace FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubFeatures;
|
||||
|
||||
/// <summary>
|
||||
/// دریافت لیست فیچرهای باشگاه مشتریان برای کاربر جاری
|
||||
/// </summary>
|
||||
public record GetClubFeaturesQuery : IRequest<GetClubFeaturesResponseDto>;
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
using CMSMicroservice.Protobuf.Protos.ClubMembership;
|
||||
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||
|
||||
namespace FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubFeatures;
|
||||
|
||||
/// <summary>
|
||||
/// هندلر دریافت فیچرهای باشگاه مشتریان برای کاربر جاری
|
||||
/// </summary>
|
||||
public class GetClubFeaturesQueryHandler : IRequestHandler<GetClubFeaturesQuery, GetClubFeaturesResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
|
||||
public GetClubFeaturesQueryHandler(
|
||||
IApplicationContractContext context,
|
||||
ICurrentUserService currentUser)
|
||||
{
|
||||
_context = context;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
public async Task<GetClubFeaturesResponseDto> Handle(GetClubFeaturesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// دریافت فیچرهای باشگاه برای کاربر جاری
|
||||
var getUserFeaturesRequest = new GetUserClubFeaturesRequest
|
||||
{
|
||||
UserId = _currentUser.UserId ?? 0
|
||||
};
|
||||
|
||||
var response = await _context.ClubMemberships.GetUserClubFeaturesAsync(
|
||||
getUserFeaturesRequest,
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
var result = new GetClubFeaturesResponseDto
|
||||
{
|
||||
Features = response.Features.Select(f => new ClubFeatureItemDto
|
||||
{
|
||||
Id = f.ClubFeatureId,
|
||||
Title = f.FeatureTitle ?? string.Empty,
|
||||
Description = f.FeatureDescription,
|
||||
IsEnabled = f.IsActive,
|
||||
DisplayOrder = f.SortOrder,
|
||||
GrantedAt = f.GrantedAt?.ToDateTime() ?? DateTime.MinValue,
|
||||
CreatedAt = f.CreatedAt?.ToDateTime() ?? DateTime.MinValue,
|
||||
Notes = f.Notes
|
||||
})
|
||||
.OrderBy(f => f.DisplayOrder)
|
||||
.ToList()
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
namespace FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubFeatures;
|
||||
|
||||
public class GetClubFeaturesResponseDto
|
||||
{
|
||||
public List<ClubFeatureItemDto> Features { get; set; } = new();
|
||||
}
|
||||
|
||||
public class ClubFeatureItemDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public int DisplayOrder { get; set; }
|
||||
public DateTime GrantedAt { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public string? Notes { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user