Skip to content

Commit

Permalink
fix: sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev committed Jul 26, 2024
1 parent 99be073 commit a329775
Showing 1 changed file with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using GraphQL;
using MediatR;
using VirtoCommerce.CartModule.Core.Model;
using VirtoCommerce.CartModule.Core.Services;
using VirtoCommerce.CustomerModule.Core.Services;
using VirtoCommerce.Platform.Core.Common;
Expand Down Expand Up @@ -78,19 +76,6 @@ public virtual async Task<CustomerOrderAggregate> Handle(CreateOrderFromCartComm
return result;
}

protected virtual async Task ValidateCart(CartAggregate cartAggregate)
{
var context = await _cartValidationContextFactory.CreateValidationContextAsync(cartAggregate);
await cartAggregate.ValidateAsync(context, ValidationRuleSet);

var errors = cartAggregate.ValidationErrors;
if (errors.Any())
{
var dictionary = errors.GroupBy(x => x.ErrorCode).ToDictionary(x => x.Key, x => x.Select(y => y.ErrorMessage).FirstOrDefault());
throw new ExecutionError("The cart has validation errors", dictionary) { Code = Constants.ValidationErrorCode };
}
}

private async Task UpdateCart(CartAggregate cartAggregate)
{
// remove unselected gifts before order create
Expand All @@ -108,11 +93,17 @@ private async Task UpdateCart(CartAggregate cartAggregate)
}
}

[Obsolete("Use ValidateCart(CartAggregate cartAggregate)()", DiagnosticId = "VC0005", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")]
protected virtual async Task ValidateCart(ShoppingCart cart)
protected virtual async Task ValidateCart(CartAggregate cartAggregate)
{
var cartAggregate = await _cartRepository.GetCartForShoppingCartAsync(cart);
await ValidateCart(cartAggregate);
var context = await _cartValidationContextFactory.CreateValidationContextAsync(cartAggregate);
await cartAggregate.ValidateAsync(context, ValidationRuleSet);

var errors = cartAggregate.ValidationErrors;
if (errors.Any())
{
var dictionary = errors.GroupBy(x => x.ErrorCode).ToDictionary(x => x.Key, x => x.Select(y => y.ErrorMessage).FirstOrDefault());
throw new ExecutionError("The cart has validation errors", dictionary) { Code = Constants.ValidationErrorCode };
}
}
}
}

0 comments on commit a329775

Please sign in to comment.