feat: Add Protobuf definitions for Network Membership service
- Introduced `networkmembership.proto` with RPC methods for retrieving user network tree, statistics, and position. - Implemented HTTP annotations for gRPC transcoding in the service methods. - Added support for Google API annotations in `annotations.proto` and `http.proto`. - Created `ConfigureServices.cs` to register FluentValidation for the Protobuf services. - Updated project file to include necessary dependencies for gRPC and Protobuf.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
namespace FrontOffice.BFF.Application.DiscountShopCQ.Commands.AddToDiscountCart;
|
||||
|
||||
/// <summary>
|
||||
/// افزودن محصول به سبد خرید تخفیفی
|
||||
/// </summary>
|
||||
public record AddToDiscountCartCommand : IRequest<AddToDiscountCartResponseDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// شناسه محصول
|
||||
/// </summary>
|
||||
public long ProductId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// تعداد
|
||||
/// </summary>
|
||||
public int Count { get; init; } = 1;
|
||||
}
|
||||
|
||||
public class AddToDiscountCartResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountShoppingCart;
|
||||
|
||||
namespace FrontOffice.BFF.Application.DiscountShopCQ.Commands.AddToDiscountCart;
|
||||
|
||||
public class AddToDiscountCartCommandHandler : IRequestHandler<AddToDiscountCartCommand, AddToDiscountCartResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
|
||||
public AddToDiscountCartCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
|
||||
{
|
||||
_context = context;
|
||||
_currentUserService = currentUserService;
|
||||
}
|
||||
|
||||
public async Task<AddToDiscountCartResponseDto> Handle(AddToDiscountCartCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = _currentUserService.UserId ?? throw new UnauthorizedAccessException("User not authenticated");
|
||||
|
||||
var response = await _context.DiscountCart.AddToCartAsync(new AddToCartRequest
|
||||
{
|
||||
UserId = userId,
|
||||
ProductId = request.ProductId,
|
||||
Count = request.Count
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
return new AddToDiscountCartResponseDto
|
||||
{
|
||||
Success = response.Success,
|
||||
Message = response.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace FrontOffice.BFF.Application.DiscountShopCQ.Commands.PlaceDiscountOrder;
|
||||
|
||||
/// <summary>
|
||||
/// ثبت سفارش از سبد خرید تخفیفی
|
||||
/// </summary>
|
||||
public record PlaceDiscountOrderCommand : IRequest<PlaceDiscountOrderResponseDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// شناسه آدرس کاربر
|
||||
/// </summary>
|
||||
public long UserAddressId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// مقدار استفاده از موجودی تخفیف (اختیاری)
|
||||
/// </summary>
|
||||
public long DiscountBalanceToUse { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// توضیحات
|
||||
/// </summary>
|
||||
public string? Notes { get; init; }
|
||||
}
|
||||
|
||||
public class PlaceDiscountOrderResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
public long OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// مبلغ قابل پرداخت از درگاه
|
||||
/// </summary>
|
||||
public long GatewayAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// لینک پرداخت (اگر نیاز باشد)
|
||||
/// </summary>
|
||||
public string? PaymentUrl { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||||
|
||||
namespace FrontOffice.BFF.Application.DiscountShopCQ.Commands.PlaceDiscountOrder;
|
||||
|
||||
public class PlaceDiscountOrderCommandHandler : IRequestHandler<PlaceDiscountOrderCommand, PlaceDiscountOrderResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
|
||||
public PlaceDiscountOrderCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
|
||||
{
|
||||
_context = context;
|
||||
_currentUserService = currentUserService;
|
||||
}
|
||||
|
||||
public async Task<PlaceDiscountOrderResponseDto> Handle(PlaceDiscountOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = _currentUserService.UserId ?? throw new UnauthorizedAccessException("User not authenticated");
|
||||
|
||||
var cmsRequest = new PlaceOrderRequest
|
||||
{
|
||||
UserId = userId,
|
||||
UserAddressId = request.UserAddressId,
|
||||
DiscountBalanceToUse = request.DiscountBalanceToUse
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(request.Notes))
|
||||
cmsRequest.Notes = request.Notes;
|
||||
|
||||
var response = await _context.DiscountOrders.PlaceOrderAsync(cmsRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return new PlaceDiscountOrderResponseDto
|
||||
{
|
||||
Success = response.Success,
|
||||
Message = response.Message,
|
||||
OrderId = response.OrderId,
|
||||
GatewayAmount = response.GatewayAmount,
|
||||
PaymentUrl = response.PaymentUrl
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace FrontOffice.BFF.Application.DiscountShopCQ.Commands.RemoveFromDiscountCart;
|
||||
|
||||
/// <summary>
|
||||
/// حذف محصول از سبد خرید تخفیفی
|
||||
/// </summary>
|
||||
public record RemoveFromDiscountCartCommand : IRequest<RemoveFromDiscountCartResponseDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// شناسه محصول
|
||||
/// </summary>
|
||||
public long ProductId { get; init; }
|
||||
}
|
||||
|
||||
public class RemoveFromDiscountCartResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountShoppingCart;
|
||||
|
||||
namespace FrontOffice.BFF.Application.DiscountShopCQ.Commands.RemoveFromDiscountCart;
|
||||
|
||||
public class RemoveFromDiscountCartCommandHandler : IRequestHandler<RemoveFromDiscountCartCommand, RemoveFromDiscountCartResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
|
||||
public RemoveFromDiscountCartCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
|
||||
{
|
||||
_context = context;
|
||||
_currentUserService = currentUserService;
|
||||
}
|
||||
|
||||
public async Task<RemoveFromDiscountCartResponseDto> Handle(RemoveFromDiscountCartCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = _currentUserService.UserId ?? throw new UnauthorizedAccessException("User not authenticated");
|
||||
|
||||
var response = await _context.DiscountCart.RemoveFromCartAsync(new RemoveFromCartRequest
|
||||
{
|
||||
UserId = userId,
|
||||
ProductId = request.ProductId
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
return new RemoveFromDiscountCartResponseDto
|
||||
{
|
||||
Success = response.Success,
|
||||
Message = response.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user