Skip to content

Commit

Permalink
Merge branch 'release/3.426.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vc-ci committed Dec 20, 2023
2 parents 831e34c + 055388c commit fb20bde
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<!-- These properties will be shared for all projects -->
<PropertyGroup>
<VersionPrefix>3.425.0</VersionPrefix>
<VersionPrefix>3.426.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace VirtoCommerce.OrdersModule.Core.Model.Search
{
public class ShipmentSearchCriteria : OrderOperationSearchCriteriaBase
{
/// <summary>
/// It used to limit search within a customer order id
/// </summary>
public string OrderId { get; set; }
/// <summary>
/// It used to limit search within a customer order number
/// </summary>
public string OrderNumber { get; set; }

public string FulfillmentCenterId { get; set; }

public string ShipmentMethodCode { get; set; }

public string ShipmentMethodOption { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.OrdersModule.Core.Model.Search
{
public class ShipmentSearchResult : GenericSearchResult<Shipment>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Model.Search;
using VirtoCommerce.Platform.Core.GenericCrud;

namespace VirtoCommerce.OrdersModule.Core.Services
{
public interface IShipmentSearchService : ISearchService<ShipmentSearchCriteria, ShipmentSearchResult, Shipment>
{
}
}
94 changes: 47 additions & 47 deletions src/VirtoCommerce.OrdersModule.Data/Model/ShipmentEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,97 +278,97 @@ public override OperationEntity FromModel(OrderOperation operation, PrimaryKeyRe
return this;
}

public override void Patch(OperationEntity operation)
public override void Patch(OperationEntity target)
{
var target = operation as ShipmentEntity;
var shipmentEntity = target as ShipmentEntity;
if (target == null)
{
throw new ArgumentException(@"operation argument must be of type ShipmentEntity", nameof(operation));
throw new ArgumentException(@"operation argument must be of type ShipmentEntity", nameof(target));
}

// Patch prices if there are non 0 prices in the patching entity, or all patched entity prices are 0
var isNeedPatch = GetNonCalculatablePrices().Any(x => x != 0m) || target.GetNonCalculatablePrices().All(x => x == 0m);

base.NeedPatchSum = isNeedPatch;
base.Patch(operation);

target.FulfillmentCenterId = FulfillmentCenterId;
target.FulfillmentCenterName = FulfillmentCenterName;
target.OrganizationId = OrganizationId;
target.OrganizationName = OrganizationName;
target.EmployeeId = EmployeeId;
target.EmployeeName = EmployeeName;
target.ShipmentMethodCode = ShipmentMethodCode;
target.ShipmentMethodOption = ShipmentMethodOption;
target.Height = Height;
target.Length = Length;
target.Weight = Weight;
target.Height = Height;
target.Width = Width;
target.MeasureUnit = MeasureUnit;
target.WeightUnit = WeightUnit;
target.Length = Length;
target.TaxType = TaxType;
target.TrackingNumber = TrackingNumber;
target.TrackingUrl = TrackingUrl;
target.DeliveryDate = DeliveryDate;
target.VendorId = VendorId;
var isNeedPatch = GetNonCalculatablePrices().Any(x => x != 0m) || shipmentEntity.GetNonCalculatablePrices().All(x => x == 0m);

NeedPatchSum = isNeedPatch;
base.Patch(target);

shipmentEntity.FulfillmentCenterId = FulfillmentCenterId;
shipmentEntity.FulfillmentCenterName = FulfillmentCenterName;
shipmentEntity.OrganizationId = OrganizationId;
shipmentEntity.OrganizationName = OrganizationName;
shipmentEntity.EmployeeId = EmployeeId;
shipmentEntity.EmployeeName = EmployeeName;
shipmentEntity.ShipmentMethodCode = ShipmentMethodCode;
shipmentEntity.ShipmentMethodOption = ShipmentMethodOption;
shipmentEntity.Height = Height;
shipmentEntity.Length = Length;
shipmentEntity.Weight = Weight;
shipmentEntity.Height = Height;
shipmentEntity.Width = Width;
shipmentEntity.MeasureUnit = MeasureUnit;
shipmentEntity.WeightUnit = WeightUnit;
shipmentEntity.Length = Length;
shipmentEntity.TaxType = TaxType;
shipmentEntity.TrackingNumber = TrackingNumber;
shipmentEntity.TrackingUrl = TrackingUrl;
shipmentEntity.DeliveryDate = DeliveryDate;
shipmentEntity.VendorId = VendorId;

if (isNeedPatch)
{
target.Price = Price;
target.PriceWithTax = PriceWithTax;
target.DiscountAmount = DiscountAmount;
target.DiscountAmountWithTax = DiscountAmountWithTax;
target.TaxPercentRate = TaxPercentRate;
target.TaxTotal = TaxTotal;
target.Total = Total;
target.TotalWithTax = TotalWithTax;
target.Fee = Fee;
target.FeeWithTax = FeeWithTax;
shipmentEntity.Price = Price;
shipmentEntity.PriceWithTax = PriceWithTax;
shipmentEntity.DiscountAmount = DiscountAmount;
shipmentEntity.DiscountAmountWithTax = DiscountAmountWithTax;
shipmentEntity.TaxPercentRate = TaxPercentRate;
shipmentEntity.TaxTotal = TaxTotal;
shipmentEntity.Total = Total;
shipmentEntity.TotalWithTax = TotalWithTax;
shipmentEntity.Fee = Fee;
shipmentEntity.FeeWithTax = FeeWithTax;
}

if (!InPayments.IsNullCollection())
{
InPayments.Patch(target.InPayments, (sourcePayment, targetPayment) => sourcePayment.Patch(targetPayment));
InPayments.Patch(shipmentEntity.InPayments, (sourcePayment, targetPayment) => sourcePayment.Patch(targetPayment));
}

if (!Items.IsNullCollection())
{
Items.Patch(target.Items, (sourceItem, targetItem) => sourceItem.Patch(targetItem));
Items.Patch(shipmentEntity.Items, (sourceItem, targetItem) => sourceItem.Patch(targetItem));
}

if (!Discounts.IsNullCollection())
{
var discountComparer = AnonymousComparer.Create((DiscountEntity x) => x.PromotionId);
Discounts.Patch(target.Discounts, discountComparer, (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount));
Discounts.Patch(shipmentEntity.Discounts, discountComparer, (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount));
}

if (!Addresses.IsNullCollection())
{
Addresses.Patch(target.Addresses, (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress));
Addresses.Patch(shipmentEntity.Addresses, (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress));
}

if (!Packages.IsNullCollection())
{
Packages.Patch(target.Packages, (sourcePackage, targetPackage) => sourcePackage.Patch(targetPackage));
Packages.Patch(shipmentEntity.Packages, (sourcePackage, targetPackage) => sourcePackage.Patch(targetPackage));
}

if (!TaxDetails.IsNullCollection())
{
var taxDetailComparer = AnonymousComparer.Create((TaxDetailEntity x) => x.Name);
TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail));
TaxDetails.Patch(shipmentEntity.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail));
}

if (!FeeDetails.IsNullCollection())
{
var feeDetailComparer = AnonymousComparer.Create((FeeDetailEntity x) => x.FeeId);
FeeDetails.Patch(target.FeeDetails, feeDetailComparer, (sourceFeeDetail, targetFeeDetail) => sourceFeeDetail.Patch(targetFeeDetail));
FeeDetails.Patch(shipmentEntity.FeeDetails, feeDetailComparer, (sourceFeeDetail, targetFeeDetail) => sourceFeeDetail.Patch(targetFeeDetail));
}

if (!DynamicPropertyObjectValues.IsNullCollection())
{
DynamicPropertyObjectValues.Patch(target.DynamicPropertyObjectValues, (sourceDynamicPropertyObjectValues, targetDynamicPropertyObjectValues) => sourceDynamicPropertyObjectValues.Patch(targetDynamicPropertyObjectValues));
DynamicPropertyObjectValues.Patch(shipmentEntity.DynamicPropertyObjectValues, (sourceDynamicPropertyObjectValues, targetDynamicPropertyObjectValues) => sourceDynamicPropertyObjectValues.Patch(targetDynamicPropertyObjectValues));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override IQueryable<PaymentInEntity> BuildQuery(IRepository repository
query = query.Where(x => criteria.HasParentOperation.Value ? x.ParentOperationId != null : x.ParentOperationId == null);
}

if (criteria.ParentOperationId != null)
if (!string.IsNullOrEmpty(criteria.ParentOperationId))
{
query = query.Where(x => x.ParentOperationId == criteria.ParentOperationId);
}
Expand All @@ -55,7 +55,7 @@ protected override IQueryable<PaymentInEntity> BuildQuery(IRepository repository
query = query.Where(x => x.CustomerOrder.Number == criteria.OrderNumber);
}

if (criteria.EmployeeId != null)
if (!string.IsNullOrEmpty(criteria.EmployeeId))
{
query = query.Where(x => x.CustomerOrder.EmployeeId == criteria.EmployeeId);
}
Expand Down
132 changes: 132 additions & 0 deletions src/VirtoCommerce.OrdersModule.Data/Services/ShipmentSearchService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.Extensions.Options;
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Model.Search;
using VirtoCommerce.OrdersModule.Core.Services;
using VirtoCommerce.OrdersModule.Data.Model;
using VirtoCommerce.OrdersModule.Data.Repositories;
using VirtoCommerce.Platform.Core.Caching;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.GenericCrud;
using VirtoCommerce.Platform.Data.GenericCrud;

namespace VirtoCommerce.OrdersModule.Data.Services
{
public class ShipmentSearchService : SearchService<ShipmentSearchCriteria, ShipmentSearchResult, Shipment, ShipmentEntity>, IShipmentSearchService
{
public ShipmentSearchService(
Func<IOrderRepository> repositoryFactory,
IPlatformMemoryCache platformMemoryCache,
IShipmentService crudService,
IOptions<CrudOptions> crudOptions)
: base(repositoryFactory, platformMemoryCache, crudService, crudOptions)
{
}


protected override IQueryable<ShipmentEntity> BuildQuery(IRepository repository, ShipmentSearchCriteria criteria)
{
var query = ((IOrderRepository)repository).Shipments;

if (!criteria.Ids.IsNullOrEmpty())
{
query = query.Where(x => criteria.Ids.Contains(x.Id));
}

if (criteria.HasParentOperation != null)
{
query = query.Where(x => criteria.HasParentOperation.Value ? x.ParentOperationId != null : x.ParentOperationId == null);
}

if (!string.IsNullOrEmpty(criteria.ParentOperationId))
{
query = query.Where(x => x.ParentOperationId == criteria.ParentOperationId);
}

if (!string.IsNullOrEmpty(criteria.OrderId))
{
query = query.Where(x => x.CustomerOrderId == criteria.OrderId);
}
else if (!string.IsNullOrEmpty(criteria.OrderNumber))
{
query = query.Where(x => x.CustomerOrder.Number == criteria.OrderNumber);
}

if (!string.IsNullOrEmpty(criteria.EmployeeId))
{
query = query.Where(x => x.CustomerOrder.EmployeeId == criteria.EmployeeId);
}

if (!criteria.StoreIds.IsNullOrEmpty())
{
query = query.Where(x => criteria.StoreIds.Contains(x.CustomerOrder.StoreId));
}

if (!criteria.Statuses.IsNullOrEmpty())
{
query = query.Where(x => criteria.Statuses.Contains(x.Status));
}

if (criteria.StartDate != null)
{
query = query.Where(x => x.CreatedDate >= criteria.StartDate);
}

if (criteria.EndDate != null)
{
query = query.Where(x => x.CreatedDate <= criteria.EndDate);
}

if (!criteria.Numbers.IsNullOrEmpty())
{
query = query.Where(x => criteria.Numbers.Contains(x.Number));
}
else if (!string.IsNullOrEmpty(criteria.Keyword))
{
query = query.Where(GetKeywordPredicate(criteria));
}

if (!string.IsNullOrEmpty(criteria.FulfillmentCenterId))
{
query = query.Where(x => x.FulfillmentCenterId == criteria.FulfillmentCenterId);
}

if (!string.IsNullOrEmpty(criteria.ShipmentMethodCode))
{
query = query.Where(x => x.ShipmentMethodCode == criteria.ShipmentMethodCode);
}

if (!string.IsNullOrEmpty(criteria.ShipmentMethodOption))
{
query = query.Where(x => x.ShipmentMethodOption == criteria.ShipmentMethodOption);
}

return query;
}

protected override IList<SortInfo> BuildSortExpression(ShipmentSearchCriteria criteria)
{
var sortInfos = criteria.SortInfos;
if (sortInfos.IsNullOrEmpty())
{
sortInfos = new[]
{
new SortInfo
{
SortColumn = nameof(ShipmentEntity.CreatedDate),
SortDirection = SortDirection.Descending
}
};
}
return sortInfos;
}

protected virtual Expression<Func<ShipmentEntity, bool>> GetKeywordPredicate(ShipmentSearchCriteria criteria)
{
return Shipment => Shipment.Number.Contains(criteria.Keyword);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Microsoft.AspNetCore.Mvc;
using VirtoCommerce.OrdersModule.Core;
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Model.Search;
using VirtoCommerce.OrdersModule.Core.Services;
using VirtoCommerce.OrdersModule.Data.Authorization;

namespace VirtoCommerce.OrdersModule.Web.Controllers.Api
{
Expand All @@ -12,10 +14,16 @@ namespace VirtoCommerce.OrdersModule.Web.Controllers.Api
public class OrderModuleShipmentsController : Controller
{
private readonly IShipmentService _shipmentService;
private readonly IShipmentSearchService _shipmentSearchService;
private readonly IAuthorizationService _authorizationService;

public OrderModuleShipmentsController(IShipmentService shipmentService)
public OrderModuleShipmentsController(IShipmentService shipmentService,
IShipmentSearchService shipmentSearchService,
IAuthorizationService authorizationService)
{
_shipmentService = shipmentService;
_shipmentSearchService = shipmentSearchService;
_authorizationService = authorizationService;
}

[HttpPost]
Expand All @@ -26,5 +34,24 @@ public async Task<ActionResult> UpdateShipment([FromBody] Shipment shipment)

return Ok();
}

/// <summary>
/// Search shipments by given criteria
/// </summary>
/// <param name="criteria">criteria</param>
[HttpPost]
[Route("search")]
public async Task<ActionResult<ShipmentSearchResult>> SearchOrderShipments([FromBody] ShipmentSearchCriteria criteria)
{
var authorizationResult = await _authorizationService.AuthorizeAsync(User, criteria, new OrderAuthorizationRequirement(ModuleConstants.Security.Permissions.Read));
if (!authorizationResult.Succeeded)
{
return Forbid();
}

var result = await _shipmentSearchService.SearchAsync(criteria);

return Ok(result);
}
}
}
Loading

0 comments on commit fb20bde

Please sign in to comment.