feat: add Configuration gRPC service and queries for club settings and features
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubConfiguration;
|
||||
using FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubFeatures;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using ProtoDto = FrontOffice.BFF.Configuration.Protobuf.Protos.Configuration;
|
||||
|
||||
namespace FrontOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class ConfigurationProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
// GetClubConfiguration mappings
|
||||
config.NewConfig<GetClubConfigurationResponseDto, ProtoDto.GetClubConfigurationResponse>()
|
||||
.Map(dest => dest.ActivationFee, src => src.ActivationFee)
|
||||
.Map(dest => dest.MembershipGiftValue, src => src.MembershipGiftValue);
|
||||
|
||||
// GetClubFeatures mappings
|
||||
config.NewConfig<GetClubFeaturesResponseDto, ProtoDto.GetClubFeaturesResponse>()
|
||||
.MapWith(src => new ProtoDto.GetClubFeaturesResponse
|
||||
{
|
||||
Features = { src.Features.Select(f => f.Adapt<ProtoDto.ClubFeatureModel>()) }
|
||||
});
|
||||
|
||||
config.NewConfig<ClubFeatureItemDto, ProtoDto.ClubFeatureModel>()
|
||||
.Map(dest => dest.Id, src => src.Id)
|
||||
.Map(dest => dest.Title, src => src.Title)
|
||||
.Map(dest => dest.Description, src => src.Description ?? "")
|
||||
.Map(dest => dest.IsEnabled, src => src.IsEnabled)
|
||||
.Map(dest => dest.DisplayOrder, src => src.DisplayOrder)
|
||||
.Map(dest => dest.GrantedAt, src => src.GrantedAt != DateTime.MinValue
|
||||
? Timestamp.FromDateTime(DateTime.SpecifyKind(src.GrantedAt, DateTimeKind.Utc))
|
||||
: null)
|
||||
.Map(dest => dest.CreatedAt, src => src.CreatedAt != DateTime.MinValue
|
||||
? Timestamp.FromDateTime(DateTime.SpecifyKind(src.CreatedAt, DateTimeKind.Utc))
|
||||
: null)
|
||||
.Map(dest => dest.Notes, src => src.Notes ?? "");
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.DiscountShop.Protobuf\FrontOffice.BFF.DiscountShop.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.Commission.Protobuf\FrontOffice.BFF.Commission.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.ClubMembership.Protobuf\FrontOffice.BFF.ClubMembership.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.Configuration.Protobuf\FrontOffice.BFF.Configuration.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.NetworkMembership.Protobuf\FrontOffice.BFF.NetworkMembership.Protobuf.csproj" />
|
||||
<ProjectReference Include="..\Protobufs\FrontOffice.BFF.City.Protobuf\FrontOffice.BFF.City.Protobuf.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using FrontOffice.BFF.WebApi.Common.Services;
|
||||
using FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubConfiguration;
|
||||
using FrontOffice.BFF.Application.ConfigurationCQ.Queries.GetClubFeatures;
|
||||
using FrontOffice.BFF.Configuration.Protobuf.Protos.Configuration;
|
||||
|
||||
namespace FrontOffice.BFF.WebApi.Services;
|
||||
|
||||
/// <summary>
|
||||
/// سرویس تنظیمات - برای کاربران FrontOffice
|
||||
/// </summary>
|
||||
public class ConfigurationGrpcService : ConfigurationContract.ConfigurationContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
|
||||
public ConfigurationGrpcService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// دریافت تنظیمات باشگاه مشتریان
|
||||
/// </summary>
|
||||
public override async Task<GetClubConfigurationResponse> GetClubConfiguration(Empty request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetClubConfigurationQuery, GetClubConfigurationResponse>(context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// دریافت لیست فیچرهای باشگاه مشتریان
|
||||
/// </summary>
|
||||
public override async Task<GetClubFeaturesResponse> GetClubFeatures(Empty request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetClubFeaturesQuery, GetClubFeaturesResponse>(context);
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,19 @@ using FrontOffice.BFF.Application.UserOrderCQ.Queries.GetAllUserOrderByFilter;
|
||||
using FrontOffice.BFF.Application.UserOrderCQ.Queries.GetVATRate;
|
||||
using FrontOffice.BFF.Application.UserOrderCQ.Commands.SubmitShopBuyOrder;
|
||||
using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder;
|
||||
using MediatR;
|
||||
using Mapster;
|
||||
|
||||
namespace FrontOffice.BFF.WebApi.Services;
|
||||
public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
private readonly ISender _mediator;
|
||||
|
||||
public UserOrderService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
public UserOrderService(IDispatchRequestToCQRS dispatchRequestToCQRS, ISender mediator)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
_mediator = mediator;
|
||||
}
|
||||
public override async Task<CreateNewUserOrderResponse> CreateNewUserOrder(CreateNewUserOrderRequest request, ServerCallContext context)
|
||||
{
|
||||
@@ -44,6 +48,7 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
|
||||
public override async Task<GetVATRateResponse> GetVATRate(Empty request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<Empty, GetVATRateQuery, GetVATRateResponse>(request, context);
|
||||
var result = await _mediator.Send(new GetVATRateQuery());
|
||||
return result.Adapt<GetVATRateResponse>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user