fix: PaymentStatus→PaymentCompleted mapping in DiscountOrderService
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m25s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m25s
- GetOrderById and GetUserOrders were using Mapster auto-mapping which could not map 'PaymentStatus' (enum: Success=0) to 'payment_completed' (bool) - Replaced with manual mapping: PaymentStatus == Success → true - Also maps DeliveryStatus and all other fields correctly - Fixed FrontOfficeBaseUrl and CmsBaseUrl to use HTTP for local dev
This commit is contained in:
@@ -8,7 +8,9 @@ using CMSMicroservice.Application.DiscountShopCQ.Queries.GetOrderById;
|
||||
using CMSMicroservice.Application.DiscountShopCQ.Queries.GetUserOrders;
|
||||
using CMSMicroservice.Application.DiscountShopCQ.Queries.GetAllDiscountOrders;
|
||||
using CMSMicroservice.Application.DiscountShopCQ.Queries.GetDiscountSalesReport;
|
||||
using DomainEnums = CMSMicroservice.Domain.Enums;
|
||||
using Grpc.Core;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Mapster;
|
||||
using MediatR;
|
||||
|
||||
@@ -79,7 +81,52 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
|
||||
UserId = GetCurrentUserId()
|
||||
};
|
||||
var result = await _sender.Send(query);
|
||||
return result.Adapt<GetOrderByIdResponse>();
|
||||
if (result == null)
|
||||
throw new RpcException(new Status(StatusCode.NotFound, "سفارش یافت نشد"));
|
||||
|
||||
var response = new GetOrderByIdResponse
|
||||
{
|
||||
Id = result.Id,
|
||||
UserId = result.UserId,
|
||||
TotalPrice = result.TotalAmount,
|
||||
DiscountBalanceUsed = result.DiscountBalanceUsed,
|
||||
GatewayAmount = result.GatewayAmountPaid,
|
||||
PaymentCompleted = result.PaymentStatus == DomainEnums.PaymentStatus.Success,
|
||||
DeliveryStatus = (DeliveryStatus)(int)result.DeliveryStatus,
|
||||
Created = Timestamp.FromDateTime(DateTime.SpecifyKind(result.Created, DateTimeKind.Utc)),
|
||||
};
|
||||
|
||||
if (result.TrackingCode != null) response.TrackingCode = result.TrackingCode;
|
||||
if (result.DeliveryDescription != null) response.Notes = result.DeliveryDescription;
|
||||
|
||||
if (result.Address != null)
|
||||
{
|
||||
response.Address = new AddressInfo
|
||||
{
|
||||
Title = result.Address.Title ?? "",
|
||||
Address = result.Address.Address ?? "",
|
||||
PostalCode = result.Address.PostalCode ?? ""
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var item in result.Items)
|
||||
{
|
||||
response.Items.Add(new CMSMicroservice.Protobuf.Protos.DiscountOrder.OrderItemDto
|
||||
{
|
||||
ProductId = item.ProductId,
|
||||
ProductTitle = item.ProductTitle ?? "",
|
||||
UnitPrice = item.UnitPrice,
|
||||
MaxDiscountPercent = item.DiscountPercentUsed,
|
||||
Count = item.Count,
|
||||
TotalPrice = item.UnitPrice * item.Count,
|
||||
DiscountAmount = item.DiscountAmount,
|
||||
FinalPrice = item.FinalPrice,
|
||||
ImagePath = item.ImagePath ?? "",
|
||||
ThumbnailPath = item.ThumbnailPath ?? ""
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<GetUserOrdersResponse> GetUserOrders(GetUserOrdersRequest request, ServerCallContext context)
|
||||
@@ -89,7 +136,30 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
|
||||
UserId = GetCurrentUserId()
|
||||
};
|
||||
var result = await _sender.Send(query);
|
||||
return result.Adapt<GetUserOrdersResponse>();
|
||||
|
||||
var response = new GetUserOrdersResponse
|
||||
{
|
||||
MetaData = result.MetaData.Adapt<CMSMicroservice.Protobuf.Protos.MetaData>()
|
||||
};
|
||||
|
||||
foreach (var o in result.Models)
|
||||
{
|
||||
var summary = new CMSMicroservice.Protobuf.Protos.DiscountOrder.OrderSummaryDto
|
||||
{
|
||||
Id = o.Id,
|
||||
TotalPrice = o.TotalAmount,
|
||||
DiscountBalanceUsed = o.DiscountBalanceUsed,
|
||||
GatewayAmount = o.GatewayAmountPaid,
|
||||
PaymentCompleted = o.PaymentStatus == DomainEnums.PaymentStatus.Success,
|
||||
DeliveryStatus = (DeliveryStatus)(int)o.DeliveryStatus,
|
||||
ItemsCount = o.ItemsCount,
|
||||
Created = Timestamp.FromDateTime(DateTime.SpecifyKind(o.Created, DateTimeKind.Utc)),
|
||||
};
|
||||
if (o.TrackingCode != null) summary.TrackingCode = o.TrackingCode;
|
||||
response.Models.Add(summary);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<GetAllDiscountOrdersResponse> GetAllDiscountOrders(GetAllDiscountOrdersRequest request, ServerCallContext context)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
"MerchantId": "00000000-0000-0000-0000-000000000000",
|
||||
"UseSandbox": true
|
||||
},
|
||||
"CmsBaseUrl": "https://localhost:32846",
|
||||
"FrontOfficeBaseUrl": "https://localhost:5268",
|
||||
"CmsBaseUrl": "http://localhost:32847",
|
||||
"FrontOfficeBaseUrl": "http://localhost:5268",
|
||||
"JwtSecurityKey": "TvlZVx5TJaHs8e9HgUdGzhGP2CIidoI444nAj+8+g7c=",
|
||||
"JwtIssuer": "https://localhost",
|
||||
"JwtAudience": "https://localhost",
|
||||
|
||||
Reference in New Issue
Block a user