refactor: update user address models and methods to use CustomerAddressModel across multiple components
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 3m8s
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 3m8s
This commit is contained in:
@@ -71,7 +71,7 @@ public class CartService
|
||||
{
|
||||
if (existing is null)
|
||||
{
|
||||
await _client.AddNewUserCartAsync(new AddNewUserCartRequest
|
||||
await _client.AddNewUserCartForCustomerAsync(new AddNewUserCartForCustomerRequest
|
||||
{
|
||||
ProductId = product.Id,
|
||||
Count = newQuantity
|
||||
@@ -80,10 +80,9 @@ public class CartService
|
||||
}
|
||||
else
|
||||
{
|
||||
await _client.UpdateUserCartAsync(new UpdateUserCartRequest
|
||||
await _client.UpdateUserCartForCustomerAsync(new UpdateUserCartForCustomerRequest
|
||||
{
|
||||
UserCartId = existing.cartId,
|
||||
|
||||
CartItemId = existing.cartId,
|
||||
Count = newQuantity
|
||||
});
|
||||
}
|
||||
@@ -112,9 +111,9 @@ public class CartService
|
||||
|
||||
try
|
||||
{
|
||||
await _client.UpdateUserCartAsync(new UpdateUserCartRequest
|
||||
await _client.UpdateUserCartForCustomerAsync(new UpdateUserCartForCustomerRequest
|
||||
{
|
||||
UserCartId = existing.cartId,
|
||||
CartItemId = existing.cartId,
|
||||
Count = quantity
|
||||
});
|
||||
}
|
||||
@@ -134,11 +133,10 @@ public class CartService
|
||||
|
||||
try
|
||||
{
|
||||
// Interpret Count=0 as remove from cart
|
||||
await _client.UpdateUserCartAsync(new UpdateUserCartRequest
|
||||
// Use dedicated remove endpoint
|
||||
await _client.RemoveUserCartForCustomerAsync(new RemoveUserCartForCustomerRequest
|
||||
{
|
||||
UserCartId = cartId,
|
||||
Count = 0
|
||||
CartItemId = cartId
|
||||
});
|
||||
}
|
||||
catch
|
||||
@@ -158,12 +156,11 @@ public class CartService
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var id in productIds)
|
||||
foreach (var item in productIds)
|
||||
{
|
||||
await _client.UpdateUserCartAsync(new UpdateUserCartRequest
|
||||
await _client.RemoveUserCartForCustomerAsync(new RemoveUserCartForCustomerRequest
|
||||
{
|
||||
UserCartId = id,
|
||||
Count = 0
|
||||
CartItemId = item
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,19 @@ namespace FrontOffice.Main.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Service for Club Membership operations
|
||||
/// Connected to FrontOffice.BFF gRPC ClubMembershipCQ
|
||||
/// Connected to CMS gRPC ClubMembershipCQ
|
||||
/// </summary>
|
||||
public class ClubMembershipService
|
||||
{
|
||||
private readonly ClubMembershipContract.ClubMembershipContractClient _client;
|
||||
private readonly UserAuthInfo _authInfo;
|
||||
|
||||
public ClubMembershipService(ClubMembershipContract.ClubMembershipContractClient client)
|
||||
public ClubMembershipService(
|
||||
ClubMembershipContract.ClubMembershipContractClient client,
|
||||
UserAuthInfo authInfo)
|
||||
{
|
||||
_client = client;
|
||||
_authInfo = authInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -24,8 +28,8 @@ public class ClubMembershipService
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = await GetCurrentUserIdAsync();
|
||||
var response = await _client.GetClubMembershipAsync(new GetClubMembershipRequest { UserId = userId });
|
||||
// UserId = 0 میفرستیم تا CMS از JWT بخونه
|
||||
var response = await _client.GetClubMembershipAsync(new GetClubMembershipRequest { UserId = 0 });
|
||||
return new ClubMembershipDto
|
||||
{
|
||||
UserId = response.UserId,
|
||||
@@ -34,8 +38,11 @@ public class ClubMembershipService
|
||||
DaysRemaining = response.DaysRemaining > 0 ? response.DaysRemaining : null
|
||||
};
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log the error for debugging
|
||||
Console.WriteLine($"GetMyMembershipAsync error: {ex.Message}");
|
||||
|
||||
// Return empty membership if backend is unavailable
|
||||
return new ClubMembershipDto
|
||||
{
|
||||
@@ -59,6 +66,19 @@ public class ClubMembershipService
|
||||
try
|
||||
{
|
||||
var userId = await GetCurrentUserIdAsync();
|
||||
|
||||
// Check if user is authenticated
|
||||
if (userId <= 0)
|
||||
{
|
||||
return new ClubActivationResponseDto
|
||||
{
|
||||
Success = false,
|
||||
Message = "کاربر احراز هویت نشده است. لطفاً ابتدا وارد شوید.",
|
||||
ActivationDate = null,
|
||||
AmountPaid = 0
|
||||
};
|
||||
}
|
||||
|
||||
var request = new ActivateClubMembershipRequest
|
||||
{
|
||||
UserId = userId,
|
||||
@@ -93,10 +113,8 @@ public class ClubMembershipService
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<long> GetCurrentUserIdAsync()
|
||||
private Task<long> GetCurrentUserIdAsync()
|
||||
{
|
||||
// Get current user ID from auth service or JWT token
|
||||
// This is a placeholder - should be implemented based on your auth system
|
||||
return 1; // TODO: Implement proper user ID retrieval
|
||||
return Task.FromResult(_authInfo.UserId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,17 @@ using Google.Protobuf.WellKnownTypes;
|
||||
namespace FrontOffice.Main.Utilities;
|
||||
|
||||
public record WalletBalances(long CreditBalance, long DiscountBalance, long NetworkBalance);
|
||||
public record WalletTransaction(string Date, long Amount, string Channel, string Description);
|
||||
public record WalletTransaction(
|
||||
string Date,
|
||||
long CreditChange,
|
||||
long CreditBalance,
|
||||
long NetworkChange,
|
||||
long NetworkBalance,
|
||||
long DiscountChange,
|
||||
long DiscountBalance,
|
||||
string Channel,
|
||||
string Description
|
||||
);
|
||||
public record WalletWithdrawal(long Id, long WeekDefinitionId, string WeekDisplayName, long Amount, int Status, int? Method, string? Iban, string Created);
|
||||
public enum WithdrawalMethodClient
|
||||
{
|
||||
@@ -52,12 +62,19 @@ public class WalletService
|
||||
request.IsIncrease = isIncrease.Value;
|
||||
}
|
||||
var response = await _client.GetCustomerWalletChangeLogAsync(request);
|
||||
|
||||
return response.Models
|
||||
.Select(t => new WalletTransaction(
|
||||
ResolveTransactionDate(t),
|
||||
t.ChangeValue != 0 ? t.ChangeValue : t.CurrentBalance,
|
||||
t.RefrenceId?.ToString() ?? "-",
|
||||
ResolveDescription(t)))
|
||||
.Select(log => new WalletTransaction(
|
||||
ResolveTransactionDate(log),
|
||||
log.ChangeValue,
|
||||
log.CurrentBalance,
|
||||
log.ChangeNerworkValue,
|
||||
log.CurrentNetworkBalance,
|
||||
log.ChangeDiscountValue,
|
||||
log.CurrentDiscountBalance,
|
||||
log.RefrenceId?.ToString() ?? "-",
|
||||
ResolveDescription(log)
|
||||
))
|
||||
.OrderByDescending(t => t.Date)
|
||||
.ToList();
|
||||
}
|
||||
@@ -74,7 +91,8 @@ public class WalletService
|
||||
{
|
||||
try
|
||||
{
|
||||
return model.CreatedAt.ToDateTime().MiladiToJalaliWithTime();
|
||||
var utcDate = model.CreatedAt.ToDateTime();
|
||||
return utcDate.ToLocalTime().MiladiToJalaliWithTime();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -87,9 +105,18 @@ public class WalletService
|
||||
|
||||
private static string ResolveDescription(CustomerWalletChangeLogModel model)
|
||||
{
|
||||
if (model.ChangeValue > 0) return "شارژ کیف پول";
|
||||
if (model.ChangeValue < 0) return "برداشت/خرید";
|
||||
return "تراکنش کیف پول";
|
||||
var parts = new List<string>();
|
||||
|
||||
if (model.ChangeValue != 0)
|
||||
parts.Add(model.ChangeValue > 0 ? "شارژ عادی" : "برداشت عادی");
|
||||
|
||||
if (model.ChangeNerworkValue != 0)
|
||||
parts.Add(model.ChangeNerworkValue > 0 ? "دریافت شبکه" : "برداشت شبکه");
|
||||
|
||||
if (model.ChangeDiscountValue != 0)
|
||||
parts.Add(model.ChangeDiscountValue > 0 ? "شارژ تخفیفی" : "خرید تخفیفی");
|
||||
|
||||
return parts.Count > 0 ? string.Join(" | ", parts) : "تراکنش کیف پول";
|
||||
}
|
||||
|
||||
public async Task<bool> RequestWithdrawalAsync(long payoutId, WithdrawalMethodClient method, string? iban)
|
||||
|
||||
Reference in New Issue
Block a user