feat: enhance user club feature management with sorting and creation timestamps
This commit is contained in:
+4
-1
@@ -31,8 +31,11 @@ public class GetUserClubFeaturesQueryHandler : IRequestHandler<GetUserClubFeatur
|
||||
FeatureDescription = ucf.ClubFeature.Description,
|
||||
IsActive = ucf.IsActive,
|
||||
GrantedAt = ucf.GrantedAt,
|
||||
Notes = ucf.Notes
|
||||
Notes = ucf.Notes,
|
||||
SortOrder = ucf.ClubFeature.SortOrder,
|
||||
CreatedAt = ucf.Created
|
||||
})
|
||||
.OrderBy(ucf => ucf.SortOrder)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return userClubFeatures;
|
||||
|
||||
+12
-2
@@ -31,7 +31,7 @@ public class UserClubFeatureDto
|
||||
public string FeatureTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// توضیحات ویژگی
|
||||
/// توضیحات کوتاه ویژگی
|
||||
/// </summary>
|
||||
public string? FeatureDescription { get; set; }
|
||||
|
||||
@@ -46,7 +46,17 @@ public class UserClubFeatureDto
|
||||
public DateTime GrantedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// یادداشت
|
||||
/// یادداشت (برای نمایش در مدال جزئیات)
|
||||
/// </summary>
|
||||
public string? Notes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ترتیب نمایش
|
||||
/// </summary>
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// تاریخ ایجاد رکورد
|
||||
/// </summary>
|
||||
public DateTime CreatedAt { get; set; }
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ public record UpdateUserAddressCommand : IRequest<Unit>
|
||||
//شناسه
|
||||
public long Id { get; init; }
|
||||
//شناسه کاربر
|
||||
public long UserId { get; init; }
|
||||
|
||||
//عنوان
|
||||
public string Title { get; init; }
|
||||
//آدرس
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@ public class UpdateUserAddressCommandValidator : AbstractValidator<UpdateUserAdd
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
RuleFor(model => model.UserId)
|
||||
.NotNull();
|
||||
|
||||
RuleFor(model => model.Title)
|
||||
.NotEmpty();
|
||||
RuleFor(model => model.Address)
|
||||
|
||||
+40
@@ -32,6 +32,34 @@ public class
|
||||
if (user.UserCarts.Count == 0)
|
||||
throw new NotFoundException("UserCart", request.UserId);
|
||||
|
||||
// چک موجودی محصولات
|
||||
var outOfStockProducts = new List<string>();
|
||||
var insufficientStockProducts = new List<(string Title, int Requested, int Available)>();
|
||||
|
||||
foreach (var cartItem in user.UserCarts)
|
||||
{
|
||||
if (cartItem.Product.RemainingCount <= 0)
|
||||
{
|
||||
outOfStockProducts.Add(cartItem.Product.Title);
|
||||
}
|
||||
else if (cartItem.Product.RemainingCount < cartItem.Count)
|
||||
{
|
||||
insufficientStockProducts.Add((cartItem.Product.Title, cartItem.Count, cartItem.Product.RemainingCount));
|
||||
}
|
||||
}
|
||||
|
||||
if (outOfStockProducts.Any())
|
||||
{
|
||||
throw new Exception($"محصولات زیر ناموجود شدهاند: {string.Join("، ", outOfStockProducts)}");
|
||||
}
|
||||
|
||||
if (insufficientStockProducts.Any())
|
||||
{
|
||||
var messages = insufficientStockProducts.Select(p =>
|
||||
$"«{p.Title}»: درخواست {p.Requested} عدد، موجودی {p.Available} عدد");
|
||||
throw new Exception($"موجودی محصولات زیر کافی نیست: {string.Join(" | ", messages)}");
|
||||
}
|
||||
|
||||
if (user.UserCarts.Sum(s => s.Count * s.Product.Price) != request.TotalAmount)
|
||||
throw new Exception("مبلغ سفارش با مجموع سبد خرید مطابقت ندارد.");
|
||||
|
||||
@@ -100,8 +128,20 @@ public class
|
||||
OrderId = newOrder.Id
|
||||
});
|
||||
await _context.FactorDetails.AddRangeAsync(factorDetailsList, cancellationToken);
|
||||
|
||||
// کاهش موجودی محصولات و افزایش تعداد فروش
|
||||
foreach (var cartItem in user.UserCarts)
|
||||
{
|
||||
cartItem.Product.RemainingCount -= cartItem.Count;
|
||||
cartItem.Product.SaleCount += cartItem.Count;
|
||||
}
|
||||
|
||||
user.UserCarts.Clear();
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
_logger.LogInformation("Order {OrderId} completed. Stock updated for {ProductCount} products.",
|
||||
newOrder.Id, factorDetailsList.Count());
|
||||
|
||||
var finalResult = new SubmitShopBuyOrderResponseDto()
|
||||
{
|
||||
Id = newOrder.Id,
|
||||
|
||||
Reference in New Issue
Block a user