Add delivery status and tracking details to user order
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.2.2" />
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.129" />
|
||||
<PackageReference Include="Mapster" Version="7.3.0" />
|
||||
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.0" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
namespace BackOffice.BFF.Application.UserOrderCQ.Commands.UpdateUserOrder;
|
||||
|
||||
public record UpdateUserOrderCommand : IRequest<Unit>
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
//قیمت
|
||||
public long Price { get; init; }
|
||||
//شناسه پکیج
|
||||
public long PackageId { get; init; }
|
||||
//شناسه تراکنش
|
||||
public long? TransactionId { get; init; }
|
||||
//وضعیت پرداخت
|
||||
public bool PaymentStatus { get; init; }
|
||||
//تاریخ پرداخت
|
||||
public DateTime? PaymentDate { get; init; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; init; }
|
||||
|
||||
// وضعیت ارسال (مقدار عددی DeliveryStatus)
|
||||
public int DeliveryStatus { get; init; }
|
||||
// کد رهگیری
|
||||
public string? TrackingCode { get; init; }
|
||||
// توضیحات ارسال
|
||||
public string? DeliveryDescription { get; init; }
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using BackOffice.BFF.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
|
||||
namespace BackOffice.BFF.Application.UserOrderCQ.Commands.UpdateUserOrder;
|
||||
|
||||
public class UpdateUserOrderCommandHandler : IRequestHandler<UpdateUserOrderCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
@@ -12,7 +14,33 @@ public class UpdateUserOrderCommandHandler : IRequestHandler<UpdateUserOrderComm
|
||||
|
||||
public async Task<Unit> Handle(UpdateUserOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _context.UserOrders.UpdateUserOrderAsync(request.Adapt<UpdateUserOrderRequest>(), cancellationToken: cancellationToken);
|
||||
// ابتدا سفارش فعلی را از CMS میگیریم تا سایر فیلدها (مبلغ، پرداخت و ...) دستنخورده بمانند
|
||||
var current = await _context.UserOrders.GetUserOrderAsync(new GetUserOrderRequest
|
||||
{
|
||||
Id = request.Id
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
if (current is null)
|
||||
return Unit.Value;
|
||||
|
||||
// ساخت درخواست کامل برای UpdateUserOrder در CMS
|
||||
var updateRequest = new UpdateUserOrderRequest
|
||||
{
|
||||
Id = current.Id,
|
||||
Amount = current.Amount,
|
||||
PackageId = current.PackageId,
|
||||
TransactionId = current.TransactionId,
|
||||
PaymentStatus = current.PaymentStatus,
|
||||
PaymentDate = current.PaymentDate,
|
||||
UserId = current.UserId,
|
||||
UserAddressId = current.UserAddressId,
|
||||
PaymentMethod = current.PaymentMethod,
|
||||
DeliveryStatus = (CMSMicroservice.Protobuf.Protos.DeliveryStatus)request.DeliveryStatus,
|
||||
TrackingCode = request.TrackingCode ?? string.Empty,
|
||||
DeliveryDescription = request.DeliveryDescription ?? string.Empty
|
||||
};
|
||||
|
||||
await _context.UserOrders.UpdateUserOrderAsync(updateRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
namespace BackOffice.BFF.Application.UserOrderCQ.Commands.UpdateUserOrder;
|
||||
|
||||
public class UpdateUserOrderCommandValidator : AbstractValidator<UpdateUserOrderCommand>
|
||||
{
|
||||
public UpdateUserOrderCommandValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
RuleFor(model => model.Price)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PackageId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PaymentStatus)
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
// سایر فیلدها اختیاری هستند (فقط برای بهروزرسانی وضعیت ارسال)
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdateUserOrderCommand>.CreateWithOptions((UpdateUserOrderCommand)model, x => x.IncludeProperties(propertyName)));
|
||||
|
||||
@@ -6,7 +6,9 @@ public class GetAllUserOrderByFilterResponseDto
|
||||
//مدل خروجی
|
||||
public List<GetAllUserOrderByFilterResponseModel>? Models { get; set; }
|
||||
|
||||
}public class GetAllUserOrderByFilterResponseModel
|
||||
}
|
||||
|
||||
public class GetAllUserOrderByFilterResponseModel
|
||||
{
|
||||
//شناسه
|
||||
public long Id { get; set; }
|
||||
@@ -16,10 +18,24 @@ public class GetAllUserOrderByFilterResponseDto
|
||||
public long PackageId { get; set; }
|
||||
//شناسه تراکنش
|
||||
public long? TransactionId { get; set; }
|
||||
//وضعیت پرداخت
|
||||
//وضعیت پرداخت (true برای Success)
|
||||
public bool PaymentStatus { get; set; }
|
||||
//تاریخ پرداخت
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
//شناسه آدرس کاربر
|
||||
public long? UserAddressId { get; set; }
|
||||
//متن آدرس کاربر
|
||||
public string? UserAddressText { get; set; }
|
||||
//وضعیت ارسال (مقدار عددی DeliveryStatus)
|
||||
public int DeliveryStatus { get; set; }
|
||||
//کد رهگیری
|
||||
public string? TrackingCode { get; set; }
|
||||
//توضیحات ارسال
|
||||
public string? DeliveryDescription { get; set; }
|
||||
// نام کامل کاربر
|
||||
public string? UserFullName { get; set; }
|
||||
// کدملی کاربر
|
||||
public string? UserNationalCode { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace BackOffice.BFF.Application.UserOrderCQ.Queries.GetUserOrder;
|
||||
|
||||
public class GetUserOrderResponseDto
|
||||
{
|
||||
//شناسه
|
||||
@@ -9,11 +10,36 @@ public class GetUserOrderResponseDto
|
||||
public long PackageId { get; set; }
|
||||
//شناسه تراکنش
|
||||
public long? TransactionId { get; set; }
|
||||
//وضعیت پرداخت
|
||||
//وضعیت پرداخت (true برای Success)
|
||||
public bool PaymentStatus { get; set; }
|
||||
//تاریخ پرداخت
|
||||
public DateTime? PaymentDate { get; set; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; set; }
|
||||
|
||||
//شناسه آدرس کاربر
|
||||
public long? UserAddressId { get; set; }
|
||||
//متن آدرس کاربر
|
||||
public string? UserAddressText { get; set; }
|
||||
//جزئیات فاکتور
|
||||
public List<GetUserOrderResponseFactorDetail>? FactorDetails { get; set; }
|
||||
//وضعیت ارسال (مقدار عددی DeliveryStatus)
|
||||
public int DeliveryStatus { get; set; }
|
||||
//کد رهگیری
|
||||
public string? TrackingCode { get; set; }
|
||||
//توضیحات ارسال
|
||||
public string? DeliveryDescription { get; set; }
|
||||
// نام کامل کاربر
|
||||
public string? UserFullName { get; set; }
|
||||
// کدملی کاربر
|
||||
public string? UserNationalCode { get; set; }
|
||||
}
|
||||
|
||||
public class GetUserOrderResponseFactorDetail
|
||||
{
|
||||
public long ProductId { get; set; }
|
||||
public string ProductTitle { get; set; }
|
||||
public string? ProductThumbnailPath { get; set; }
|
||||
public long? UnitPrice { get; set; }
|
||||
public int? Count { get; set; }
|
||||
public long? UnitDiscountPrice { get; set; }
|
||||
}
|
||||
@@ -6,15 +6,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.129" />
|
||||
<PackageReference Include="Afrino.FMSMicroservice.Protobuf" Version="0.0.122" />
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.133" />
|
||||
|
||||
<PackageReference Include="Google.Protobuf" Version="3.23.3" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.54.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.72.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -13,4 +13,6 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BackOffice.BFF.Application\BackOffice.BFF.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>0.0.6</Version>
|
||||
<Version>0.0.7</Version>
|
||||
<DebugType>None</DebugType>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||
|
||||
@@ -59,12 +59,17 @@ message CreateNewUserOrderResponse
|
||||
message UpdateUserOrderRequest
|
||||
{
|
||||
int64 id = 1;
|
||||
// فیلدهای قدیمی (فعلاً برای سازگاری نگه داشته شدهاند)
|
||||
int64 price = 2;
|
||||
int64 package_id = 3;
|
||||
google.protobuf.Int64Value transaction_id = 4;
|
||||
bool payment_status = 5;
|
||||
google.protobuf.Timestamp payment_date = 6;
|
||||
int64 user_id = 7;
|
||||
// فیلدهای جدید مربوط به ارسال
|
||||
int32 delivery_status = 8;
|
||||
google.protobuf.StringValue tracking_code = 9;
|
||||
google.protobuf.StringValue delivery_description = 10;
|
||||
}
|
||||
message DeleteUserOrderRequest
|
||||
{
|
||||
@@ -83,6 +88,22 @@ message GetUserOrderResponse
|
||||
bool payment_status = 5;
|
||||
google.protobuf.Timestamp payment_date = 6;
|
||||
int64 user_id = 7;
|
||||
// شناسه آدرس کاربر
|
||||
google.protobuf.Int64Value user_address_id = 8;
|
||||
// متن آدرس کاربر
|
||||
google.protobuf.StringValue user_address_text = 9;
|
||||
// جزئیات فاکتور
|
||||
repeated FactorDetailModel factor_details = 10;
|
||||
// وضعیت ارسال (مقدار عددی از DeliveryStatus در CMS)
|
||||
int32 delivery_status = 11;
|
||||
// کد رهگیری مرسوله
|
||||
google.protobuf.StringValue tracking_code = 12;
|
||||
// توضیحات وضعیت ارسال / نکات پستی
|
||||
google.protobuf.StringValue delivery_description = 13;
|
||||
// نام کامل کاربر
|
||||
google.protobuf.StringValue user_full_name = 14;
|
||||
// کدملی کاربر
|
||||
google.protobuf.StringValue user_national_code = 15;
|
||||
}
|
||||
message GetAllUserOrderByFilterRequest
|
||||
{
|
||||
@@ -99,6 +120,7 @@ message GetAllUserOrderByFilterFilter
|
||||
google.protobuf.BoolValue payment_status = 5;
|
||||
google.protobuf.Timestamp payment_date = 6;
|
||||
google.protobuf.Int64Value user_id = 7;
|
||||
google.protobuf.Int64Value user_address_id = 8;
|
||||
}
|
||||
message GetAllUserOrderByFilterResponse
|
||||
{
|
||||
@@ -114,6 +136,31 @@ message GetAllUserOrderByFilterResponseModel
|
||||
bool payment_status = 5;
|
||||
google.protobuf.Timestamp payment_date = 6;
|
||||
int64 user_id = 7;
|
||||
// شناسه آدرس کاربر
|
||||
google.protobuf.Int64Value user_address_id = 8;
|
||||
// متن آدرس کاربر
|
||||
google.protobuf.StringValue user_address_text = 9;
|
||||
// وضعیت ارسال (مقدار عددی از DeliveryStatus در CMS)
|
||||
int32 delivery_status = 10;
|
||||
// کد رهگیری مرسوله
|
||||
google.protobuf.StringValue tracking_code = 11;
|
||||
// توضیحات وضعیت ارسال / نکات پستی
|
||||
google.protobuf.StringValue delivery_description = 12;
|
||||
// نام کامل کاربر
|
||||
google.protobuf.StringValue user_full_name = 13;
|
||||
// کدملی کاربر
|
||||
google.protobuf.StringValue user_national_code = 14;
|
||||
}
|
||||
|
||||
// جزئیات فاکتور سفارش
|
||||
message FactorDetailModel
|
||||
{
|
||||
int64 product_id = 1;
|
||||
string product_title = 2;
|
||||
google.protobuf.StringValue product_thumbnail_path = 3;
|
||||
google.protobuf.Int64Value unit_price = 4;
|
||||
google.protobuf.Int32Value count = 5;
|
||||
google.protobuf.Int64Value unit_discount_price = 6;
|
||||
}
|
||||
|
||||
message PaginationState
|
||||
|
||||
@@ -8,14 +8,7 @@ public class UpdateUserOrderRequestValidator : AbstractValidator<UpdateUserOrder
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
RuleFor(model => model.Price)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PackageId)
|
||||
.NotNull();
|
||||
RuleFor(model => model.PaymentStatus)
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
// بقیه فیلدها اختیاری هستند و فقط برای بهروزرسانی وضعیت ارسال استفاده میشوند
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user