From e4e6116b613b3db02e4091193fe1ba8bb4dbe3ae Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Sun, 5 Jun 2022 02:13:12 +0800 Subject: [PATCH] Check store to category mapping --- ...ookingOrderCreationAuthorizationHandler.cs | 23 +++++++++++++++++-- .../Dtos/GetStoreAssetCategoryListDto.cs | 12 ++++++++++ .../IStoreAssetCategoryAppService.cs | 2 +- .../StoreAssetCategoryAppService.cs | 17 ++++++++++---- .../StoreAssetCategoryController.cs | 2 +- 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application.Contracts/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/Dtos/GetStoreAssetCategoryListDto.cs diff --git a/plugins/Booking/src/EasyAbp.EShop.Orders.Booking.Application/EasyAbp/EShop/Orders/Booking/Authorization/BookingOrderCreationAuthorizationHandler.cs b/plugins/Booking/src/EasyAbp.EShop.Orders.Booking.Application/EasyAbp/EShop/Orders/Booking/Authorization/BookingOrderCreationAuthorizationHandler.cs index 45b49d9b..024504d9 100644 --- a/plugins/Booking/src/EasyAbp.EShop.Orders.Booking.Application/EasyAbp/EShop/Orders/Booking/Authorization/BookingOrderCreationAuthorizationHandler.cs +++ b/plugins/Booking/src/EasyAbp.EShop.Orders.Booking.Application/EasyAbp/EShop/Orders/Booking/Authorization/BookingOrderCreationAuthorizationHandler.cs @@ -13,6 +13,8 @@ using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories; using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos; using EasyAbp.EShop.Plugins.Booking.ProductAssets; using EasyAbp.EShop.Plugins.Booking.ProductAssets.Dtos; +using EasyAbp.EShop.Plugins.Booking.StoreAssetCategories; +using EasyAbp.EShop.Plugins.Booking.StoreAssetCategories.Dtos; using Microsoft.AspNetCore.Authorization; using Volo.Abp; @@ -22,6 +24,7 @@ namespace EasyAbp.EShop.Orders.Booking.Authorization { private readonly IPeriodSchemeAppService _periodSchemeAppService; private readonly IProductAssetAppService _productAssetAppService; + private readonly IStoreAssetCategoryAppService _storeAssetCategoryAppService; private readonly IProductAssetCategoryAppService _productAssetCategoryAppService; private readonly IAssetOccupancyAppService _assetOccupancyAppService; private readonly IBookingProductGroupDefinitionAppService _definitionAppService; @@ -29,12 +32,14 @@ namespace EasyAbp.EShop.Orders.Booking.Authorization public BookingOrderCreationAuthorizationHandler( IPeriodSchemeAppService periodSchemeAppService, IProductAssetAppService productAssetAppService, + IStoreAssetCategoryAppService storeAssetCategoryAppService, IProductAssetCategoryAppService productAssetCategoryAppService, IAssetOccupancyAppService assetOccupancyAppService, IBookingProductGroupDefinitionAppService definitionAppService) { _periodSchemeAppService = periodSchemeAppService; _productAssetAppService = productAssetAppService; + _storeAssetCategoryAppService = storeAssetCategoryAppService; _productAssetCategoryAppService = productAssetCategoryAppService; _assetOccupancyAppService = assetOccupancyAppService; _definitionAppService = definitionAppService; @@ -141,8 +146,10 @@ namespace EasyAbp.EShop.Orders.Booking.Authorization protected virtual async Task IsAssetInfoValidAsync(CreateOrderLineDto orderLine, OrderCreationResource resource) { + // Todo: check store to asset mapping. + var productAsset = (await _productAssetAppService.GetListAsync( - new GetProductAssetDto + new GetProductAssetListDto { MaxResultCount = 1, StoreId = resource.Input.StoreId, @@ -159,8 +166,20 @@ namespace EasyAbp.EShop.Orders.Booking.Authorization protected virtual async Task IsAssetCategoryInfoValidAsync(CreateOrderLineDto orderLine, OrderCreationResource resource) { + var mapping = (await _storeAssetCategoryAppService.GetListAsync(new GetStoreAssetCategoryListDto + { + MaxResultCount = 1, + StoreId = resource.Input.StoreId, + AssetCategoryId = orderLine.GetBookingAssetCategoryId() + })).Items.FirstOrDefault(); + + if (mapping is null) + { + return false; + } + var productAssetCategory = (await _productAssetCategoryAppService.GetListAsync( - new GetProductAssetCategoryDto + new GetProductAssetCategoryListDto { MaxResultCount = 1, StoreId = resource.Input.StoreId, diff --git a/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application.Contracts/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/Dtos/GetStoreAssetCategoryListDto.cs b/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application.Contracts/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/Dtos/GetStoreAssetCategoryListDto.cs new file mode 100644 index 00000000..dbc19eb8 --- /dev/null +++ b/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application.Contracts/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/Dtos/GetStoreAssetCategoryListDto.cs @@ -0,0 +1,12 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace EasyAbp.EShop.Plugins.Booking.StoreAssetCategories.Dtos; + +[Serializable] +public class GetStoreAssetCategoryListDto : PagedAndSortedResultRequestDto +{ + public Guid? StoreId { get; set; } + + public Guid? AssetCategoryId { get; set; } +} \ No newline at end of file diff --git a/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application.Contracts/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/IStoreAssetCategoryAppService.cs b/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application.Contracts/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/IStoreAssetCategoryAppService.cs index a1ef9ccb..5a2a0644 100644 --- a/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application.Contracts/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/IStoreAssetCategoryAppService.cs +++ b/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application.Contracts/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/IStoreAssetCategoryAppService.cs @@ -9,7 +9,7 @@ namespace EasyAbp.EShop.Plugins.Booking.StoreAssetCategories ICrudAppService< StoreAssetCategoryDto, Guid, - PagedAndSortedResultRequestDto, + GetStoreAssetCategoryListDto, CreateUpdateStoreAssetCategoryDto, CreateUpdateStoreAssetCategoryDto> { diff --git a/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/StoreAssetCategoryAppService.cs b/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/StoreAssetCategoryAppService.cs index 95e8a618..1c409687 100644 --- a/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/StoreAssetCategoryAppService.cs +++ b/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Application/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/StoreAssetCategoryAppService.cs @@ -1,16 +1,18 @@ using System; +using System.Linq; +using System.Threading.Tasks; using EasyAbp.EShop.Plugins.Booking.Permissions; using EasyAbp.EShop.Plugins.Booking.StoreAssetCategories.Dtos; -using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; namespace EasyAbp.EShop.Plugins.Booking.StoreAssetCategories { - public class StoreAssetCategoryAppService : CrudAppService, + public class StoreAssetCategoryAppService : CrudAppService, IStoreAssetCategoryAppService { - protected override string GetPolicyName { get; set; } = BookingPermissions.StoreAssetCategory.Default; - protected override string GetListPolicyName { get; set; } = BookingPermissions.StoreAssetCategory.Default; + protected override string GetPolicyName { get; set; } = null; + protected override string GetListPolicyName { get; set; } = null; protected override string CreatePolicyName { get; set; } = BookingPermissions.StoreAssetCategory.Create; protected override string UpdatePolicyName { get; set; } = BookingPermissions.StoreAssetCategory.Update; protected override string DeletePolicyName { get; set; } = BookingPermissions.StoreAssetCategory.Delete; @@ -21,5 +23,12 @@ namespace EasyAbp.EShop.Plugins.Booking.StoreAssetCategories { _repository = repository; } + + protected override async Task> CreateFilteredQueryAsync(GetStoreAssetCategoryListDto input) + { + return (await base.CreateFilteredQueryAsync(input)) + .WhereIf(input.StoreId.HasValue, x => x.StoreId == input.StoreId) + .WhereIf(input.AssetCategoryId.HasValue, x => x.AssetCategoryId == input.AssetCategoryId); + } } } diff --git a/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.HttpApi/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/StoreAssetCategoryController.cs b/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.HttpApi/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/StoreAssetCategoryController.cs index bf9f903d..a745c3fb 100644 --- a/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.HttpApi/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/StoreAssetCategoryController.cs +++ b/plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.HttpApi/EasyAbp/EShop/Plugins/Booking/StoreAssetCategories/StoreAssetCategoryController.cs @@ -49,7 +49,7 @@ namespace EasyAbp.EShop.Plugins.Booking.StoreAssetCategories [HttpGet] [Route("")] - public virtual Task> GetListAsync(PagedAndSortedResultRequestDto input) + public virtual Task> GetListAsync(GetStoreAssetCategoryListDto input) { return _service.GetListAsync(input); }