From 0cd0761cf53e2f2657281db24da58a22e2bc746c Mon Sep 17 00:00:00 2001 From: Suhaib Date: Fri, 12 Jul 2024 17:07:43 +0300 Subject: [PATCH] Improve MarkedItems module based on review feedback - Refactor CmsKitMarkedItemOptions to prevent duplicate entity type definitions - Enhance exception handling in DefaultMarkedItemDefinitionStore - Remove redundant GetAsync method from MarkedItemManager - Remove IQueryable exposure from IUserMarkedItemRepository - Align EntityTagRepository approach with other repositories - Rename GetForToggleAsync to GetAsync or GetForUserAsync in IMarkedItemPublicAppService These changes improve code clarity, consistency, and adherence to ABP.io best practices. --- docs/en/Modules/Cms-Kit/MarkedItems.md | 25 ------------------- .../Volo/CmsKit/CmsKitErrorCodes.cs | 2 ++ .../CmsKit/Localization/Resources/ar.json | 2 ++ .../CmsKit/Localization/Resources/en.json | 2 ++ .../DefaultMarkedItemDefinitionStore.cs | 16 ++++++++++-- .../DuplicateMarkedItemDefinitionException.cs | 16 ++++++++++++ .../MarkedItems/IUserMarkedItemRepository.cs | 5 ++-- .../MarkedItemDefinitionNotFoundException.cs | 16 ++++++++++++ .../CmsKit/MarkedItems/MarkedItemManager.cs | 10 +------- .../EfCoreUserMarkedItemRepository.cs | 23 +++++++---------- .../MongoUserMarkedItemRepository.cs | 24 ++++++++---------- .../IMarkedItemPublicAppService.cs | 2 +- .../MarkedItems/MarkedItemPublicAppService.cs | 6 ++--- .../IMarkedItemPublicAppService.cs | 2 +- .../MarkedItemPublicClientProxy.Generated.cs | 4 +-- .../ClientProxies/cms-kit-generate-proxy.json | 8 +++--- .../MarkedItems/MarkedItemPublicController.cs | 4 +-- .../MarkedItemToggleViewComponent.cs | 2 +- .../wwwroot/client-proxies/cms-kit-proxy.js | 2 +- .../MarkedItemPublicAppService_Tests.cs | 4 +-- .../MarkedItems/MarkedItemManager_Tests.cs | 13 ++-------- .../CmsKitDataSeedContributor.cs | 4 +-- .../UserMarkedItemRepository_Tests.cs | 19 +++++--------- 23 files changed, 102 insertions(+), 109 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DuplicateMarkedItemDefinitionException.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemDefinitionNotFoundException.cs diff --git a/docs/en/Modules/Cms-Kit/MarkedItems.md b/docs/en/Modules/Cms-Kit/MarkedItems.md index 198d8dae47..b7bbb77519 100644 --- a/docs/en/Modules/Cms-Kit/MarkedItems.md +++ b/docs/en/Modules/Cms-Kit/MarkedItems.md @@ -58,31 +58,6 @@ The marking system provides a toggle widget to allow users to add/remove the mar * `entityId` should be the unique id of the product, in this example. If you have a Product entity, you can use its Id here. * `needsConfirmation` An optional parameter to let the user confirm when removing the mark. -# Filter on marked items - -Filtering on marked items enhances the user experience by making it easier to search marked items. - -![markedItemsFilter](../../images/cmskit-module-markedItemsFilter.gif) - -There is an ability to utilize the marking system to let users filter on their marked items. The code below shows how you can filter on your query filter: - -```csharp - protected async override Task> CreateFilteredQueryAsync(YourEntityPagedAndSortedResultDto input) - { - IQueryable query = await base.CreateFilteredQueryAsync(input); - - if (input.FilterOnFavorites && CurrentUser.IsAuthenticated) - { - var markedQuery = await UserMarkedItemRepository.GetQueryForUserAsync("entityType", CurrentUser.GetId()); - query = query.Where(e => markedQuery.Any(m => m.EntityId == e.Id)); - } - - // ... - - return query; - } -``` - # Internals ## Domain Layer diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs index bd49a57b57..9bd0ea1044 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs @@ -48,5 +48,7 @@ public static class CmsKitErrorCodes public static class MarkedItems { public const string EntityCannotBeMarked = "CmsKit:MarkedItem:0001"; + public const string MarkedItemDefinitionNotFound = "CmsKit:MarkedItem:0002"; + public const string DuplicateMarkedItem = "CmsKit:MarkedItem:0003"; } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ar.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ar.json index 8fa7bb1951..c86c314d87 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ar.json +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ar.json @@ -26,6 +26,8 @@ "CmsKit:Rating:0001": "لا يمكن تصنيف الكيان {EntityType}.", "CmsKit:Reaction:0001": "لا يمكن أن يحتوي الكيان {EntityType} على ردود أفعال.", "CmsKit:MarkedItem:0001": "لا يمكن أن تمييز الكيان {EntityType}.", + "CmsKit:MarkedItem:0002": "لم يتم العثور على تعريف لنوع الكيان '{EntityType}'.", + "CmsKit:MarkedItem:0003": "يوجد بالفعل تعريف لنوع الكيان '{EntityType}'. يجب أن يكون لكل نوع كيان تعريف واحد فقط.", "CmsKit:Tag:0002": "الكيان غير قابل للوسم!", "CommentAuthorizationExceptionMessage": "هذه التعليقات غير مسموح بها للعرض العام.", "CommentDeletionConfirmationMessage": "سيتم حذف هذا التعليق وجميع الردود!", diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json index be039c3810..7be776daa3 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json @@ -33,6 +33,8 @@ "CmsKit:Modals:YouAreNotAuthenticated": "This operation is not authorized for you.", "CommentDeletionConfirmationMessage": "This comment and all replies will be deleted!", "CmsKit:MarkedItem:0001": "The entity {EntityType} can't be marked.", + "CmsKit:MarkedItem:0002": "No definition found for entity type '{EntityType}'.", + "CmsKit:MarkedItem:0003": "A definition for entity type '{EntityType}' already exists. Each entity type should have only one definition.", "CmsKit:MarkedItem:LoginMessage": "Please login to mark this item.", "Comments": "Comments", "Content": "Content", diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DefaultMarkedItemDefinitionStore.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DefaultMarkedItemDefinitionStore.cs index e208719740..20f23784b6 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DefaultMarkedItemDefinitionStore.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DefaultMarkedItemDefinitionStore.cs @@ -29,8 +29,20 @@ public class DefaultMarkedItemDefinitionStore : IMarkedItemDefinitionStore { Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); - var definition = Options.EntityTypes.SingleOrDefault(x => x.EntityType.Equals(entityType, StringComparison.InvariantCultureIgnoreCase)); + var definitions = Options.EntityTypes + .Where(x => x.EntityType.Equals(entityType, StringComparison.InvariantCultureIgnoreCase)) + .ToList(); - return Task.FromResult(definition); + if (definitions.Count == 0) + { + throw new MarkedItemDefinitionNotFoundException(entityType); + } + + if (definitions.Count > 1) + { + throw new DuplicateMarkedItemDefinitionException(entityType); + } + + return Task.FromResult(definitions.Single()); } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DuplicateMarkedItemDefinitionException.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DuplicateMarkedItemDefinitionException.cs new file mode 100644 index 0000000000..0d8e4c6a83 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DuplicateMarkedItemDefinitionException.cs @@ -0,0 +1,16 @@ +using JetBrains.Annotations; +using Volo.Abp; + +namespace Volo.CmsKit.MarkedItems; + +public class DuplicateMarkedItemDefinitionException : BusinessException +{ + public DuplicateMarkedItemDefinitionException([NotNull] string entityType) + { + EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType)); + Code = CmsKitErrorCodes.MarkedItems.DuplicateMarkedItem; + WithData(nameof(EntityType), EntityType); + } + + public string EntityType { get; } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/IUserMarkedItemRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/IUserMarkedItemRepository.cs index e0482a8e1b..38bd2ff2e8 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/IUserMarkedItemRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/IUserMarkedItemRepository.cs @@ -23,9 +23,10 @@ public interface IUserMarkedItemRepository : IBasicRepository> GetQueryForUserAsync( - [NotNull] string entityType, + Task> GetEntityIdsFilteredByUserAsync( [NotNull] Guid userId, + [NotNull] string entityType, + [CanBeNull] Guid? tenantId = null, CancellationToken cancellationToken = default ); } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemDefinitionNotFoundException.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemDefinitionNotFoundException.cs new file mode 100644 index 0000000000..89545fb3a4 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemDefinitionNotFoundException.cs @@ -0,0 +1,16 @@ +using JetBrains.Annotations; +using Volo.Abp; + +namespace Volo.CmsKit.MarkedItems; + +public class MarkedItemDefinitionNotFoundException : BusinessException +{ + public MarkedItemDefinitionNotFoundException([NotNull] string entityType) + { + EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType)); + Code = CmsKitErrorCodes.MarkedItems.MarkedItemDefinitionNotFound; + WithData(nameof(EntityType), EntityType); + } + + public string EntityType { get; } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemManager.cs index 8be3bfdeca..15c858f5c4 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemManager.cs @@ -18,7 +18,7 @@ public class MarkedItemManager : CmsKitDomainServiceBase MarkedItemDefinitionStore = markedItemDefinitionStore; } - public virtual async Task ToggleAsync( + public virtual async Task ToggleUserMarkedItemAsync( Guid creatorId, [NotNull] string entityType, [NotNull] string entityId) @@ -49,12 +49,4 @@ public class MarkedItemManager : CmsKitDomainServiceBase ); return true; } - - public virtual async Task GetAsync( - [NotNull] string entityType) - { - Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); - - return await MarkedItemDefinitionStore.GetAsync(entityType); - } } diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/MarkedItems/EfCoreUserMarkedItemRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/MarkedItems/EfCoreUserMarkedItemRepository.cs index 642a52d145..8f1214ffca 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/MarkedItems/EfCoreUserMarkedItemRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/MarkedItems/EfCoreUserMarkedItemRepository.cs @@ -45,23 +45,18 @@ public class EfCoreUserMarkedItemRepository : EfCoreRepository - /// Retrieves an IQueryable representing the user's marked items based on the specified entity type and user ID. - /// - /// The type of entity to filter by. - /// The ID of the user whose marked items are being retrieved. - /// Cancellation token. - /// An IQueryable representing the user's marked items filtered by the specified entity type and user ID. - public async Task> GetQueryForUserAsync([NotNull] string entityType, [NotNull] Guid userId, CancellationToken cancellationToken = default) + public async Task> GetEntityIdsFilteredByUserAsync([NotNull] Guid userId, [NotNull] string entityType, [CanBeNull] Guid? tenantId = null, CancellationToken cancellationToken = default) { - Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNull(userId, nameof(userId)); + Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); - var dbSet = await GetDbSetAsync(); - - var query = dbSet - .Where(x => x.EntityType == entityType && x.CreatorId == userId); + var dbContext = await GetDbContextAsync(); + var result = from umi in dbContext.Set() + where umi.CreatorId == userId + && umi.EntityType == entityType + && umi.TenantId == tenantId + select umi.EntityId; - return query; + return await result.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs index 9339a6cb49..91fbbf996e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs @@ -46,22 +46,18 @@ public class MongoUserMarkedItemRepository : MongoDbRepository - /// Retrieves an IQueryable representing the user's marked items based on the specified entity type and user ID. - /// - /// The type of entity to filter by. - /// The ID of the user whose marked items are being retrieved. - /// Cancellation token. - /// An IQueryable representing the user's marked items filtered by the specified entity type and user ID. - public virtual async Task> GetQueryForUserAsync([NotNull] string entityType, [NotNull] Guid userId, CancellationToken cancellationToken = default) + public virtual async Task> GetEntityIdsFilteredByUserAsync([NotNull] Guid userId, [NotNull] string entityType, [CanBeNull] Guid? tenantId = null, CancellationToken cancellationToken = default) { - Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); - Check.NotNull(userId, nameof(userId)); + var dbContext = await GetDbContextAsync(); + var userMarkedItemQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); - var queryable = await GetMongoQueryableAsync(cancellationToken); - var query = queryable - .Where(x => x.EntityType == entityType && x.CreatorId == userId); + var resultQueryable = userMarkedItemQueryable + .Where(x => x.CreatorId == userId + && x.EntityType == entityType + && x.TenantId == tenantId + ) + .Select(s => s.EntityId); - return query; + return await AsyncExecuter.ToListAsync(resultQueryable, GetCancellationToken(cancellationToken)); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs index 491a425f15..03691c4391 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs @@ -5,6 +5,6 @@ namespace Volo.CmsKit.Public.MarkedItems; public interface IMarkedItemPublicAppService : IApplicationService { - Task GetForToggleAsync(string entityType, string entityId); + Task GetForUserAsync(string entityType, string entityId); Task ToggleAsync(string entityType, string entityId); } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicAppService.cs index ea9bb5b7b4..72af653167 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicAppService.cs @@ -30,9 +30,9 @@ public class MarkedItemPublicAppService : CmsKitPublicAppServiceBase, IMarkedIte } [AllowAnonymous] - public virtual async Task GetForToggleAsync(string entityType, string entityId) + public virtual async Task GetForUserAsync(string entityType, string entityId) { - var markedItem = await MarkedItemManager.GetAsync(entityType); + var markedItem = await MarkedItemDefinitionStore.GetAsync(entityType); var userMarkedItem = CurrentUser.IsAuthenticated ? (await UserMarkedItemRepository @@ -53,7 +53,7 @@ public class MarkedItemPublicAppService : CmsKitPublicAppServiceBase, IMarkedIte [Authorize] public virtual async Task ToggleAsync(string entityType, string entityId) { - return await MarkedItemManager.ToggleAsync( + return await MarkedItemManager.ToggleUserMarkedItemAsync( CurrentUser.GetId(), entityType, entityId diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs index 51bc65d58b..5387fae58b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs @@ -12,7 +12,7 @@ namespace Volo.CmsKit.Public.MarkedItems; public interface IMarkedItemPublicAppService : IApplicationService { - Task GetForToggleAsync(string entityType, string entityId); + Task GetForUserAsync(string entityType, string entityId); Task ToggleAsync(string entityType, string entityId); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicClientProxy.Generated.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicClientProxy.Generated.cs index 31940807c7..f46c59ce6a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicClientProxy.Generated.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicClientProxy.Generated.cs @@ -17,9 +17,9 @@ namespace Volo.CmsKit.Public.MarkedItems; [ExposeServices(typeof(IMarkedItemPublicAppService), typeof(MarkedItemPublicClientProxy))] public partial class MarkedItemPublicClientProxy : ClientProxyBase, IMarkedItemPublicAppService { - public virtual async Task GetForToggleAsync(string entityType, string entityId) + public virtual async Task GetForUserAsync(string entityType, string entityId) { - return await RequestAsync(nameof(GetForToggleAsync), new ClientProxyRequestTypeValue + return await RequestAsync(nameof(GetForUserAsync), new ClientProxyRequestTypeValue { { typeof(string), entityType }, { typeof(string), entityId } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json index 6917a58fb7..b51fb76677 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json @@ -921,7 +921,7 @@ "name": "IMarkedItemPublicAppService", "methods": [ { - "name": "GetForToggleAsync", + "name": "GetForUserAsync", "parametersOnMethod": [ { "name": "entityType", @@ -974,9 +974,9 @@ } ], "actions": { - "GetForToggleAsyncByEntityTypeAndEntityId": { - "uniqueName": "GetForToggleAsyncByEntityTypeAndEntityId", - "name": "GetForToggleAsync", + "GetForUserAsyncByEntityTypeAndEntityId": { + "uniqueName": "GetForUserAsyncByEntityTypeAndEntityId", + "name": "GetForUserAsync", "httpMethod": "GET", "url": "api/cms-kit-public/marked-items/{entityType}/{entityId}", "supportedVersions": [], diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicController.cs index 9f09525f65..e000ae9ba1 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicController.cs @@ -24,9 +24,9 @@ public class MarkedItemPublicController : CmsKitPublicControllerBase, IMarkedIte [HttpGet] [Route("{entityType}/{entityId}")] - public virtual Task GetForToggleAsync(string entityType, string entityId) + public virtual Task GetForUserAsync(string entityType, string entityId) { - return MarkedItemPublicAppService.GetForToggleAsync(entityType, entityId); + return MarkedItemPublicAppService.GetForUserAsync(entityType, entityId); } [HttpPut] diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/MarkedItemToggle/MarkedItemToggleViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/MarkedItemToggle/MarkedItemToggleViewComponent.cs index 471953940d..7910d37ed2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/MarkedItemToggle/MarkedItemToggleViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/MarkedItemToggle/MarkedItemToggleViewComponent.cs @@ -36,7 +36,7 @@ public class MarkedItemToggleViewComponent : AbpViewComponent string entityId, bool? needsConfirmation = false) { - var result = await MarkedItemPublicAppService.GetForToggleAsync(entityType, entityId); + var result = await MarkedItemPublicAppService.GetForUserAsync(entityType, entityId); var returnUrl = HttpContext.Request.Path.ToString(); var viewModel = new MarkedItemToggleViewModel diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/wwwroot/client-proxies/cms-kit-proxy.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/wwwroot/client-proxies/cms-kit-proxy.js index d1a18731cb..5f5ea08ffa 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/wwwroot/client-proxies/cms-kit-proxy.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/wwwroot/client-proxies/cms-kit-proxy.js @@ -123,7 +123,7 @@ abp.utils.createNamespace(window, 'volo.cmsKit.public.markedItems.markedItemPublic'); - volo.cmsKit.public.markedItems.markedItemPublic.getForToggle = function(entityType, entityId, ajaxParams) { + volo.cmsKit.public.markedItems.markedItemPublic.getForUser = function(entityType, entityId, ajaxParams) { return abp.ajax($.extend(true, { url: abp.appPath + 'api/cms-kit-public/marked-items/' + entityType + '/' + entityId + '', type: 'GET' diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/MarkedItems/MarkedItemPublicAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/MarkedItems/MarkedItemPublicAppService_Tests.cs index e9bf6eb772..9129414023 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/MarkedItems/MarkedItemPublicAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/MarkedItems/MarkedItemPublicAppService_Tests.cs @@ -32,11 +32,11 @@ public class MarkedItemPublicAppService_Tests : CmsKitApplicationTestBase _currentUser.Id.Returns(_cmsKitTestData.User1Id); _currentUser.IsAuthenticated.Returns(true); - var firstMarkedItem = await _markedItemPublicAppService.GetForToggleAsync( + var firstMarkedItem = await _markedItemPublicAppService.GetForUserAsync( _cmsKitTestData.EntityType1, _cmsKitTestData.EntityId1 ); - var secondMarkedItem = await _markedItemPublicAppService.GetForToggleAsync( + var secondMarkedItem = await _markedItemPublicAppService.GetForUserAsync( _cmsKitTestData.EntityType2, _cmsKitTestData.EntityId1 ); diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/MarkedItems/MarkedItemManager_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/MarkedItems/MarkedItemManager_Tests.cs index 8e132932df..0d78fd8457 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/MarkedItems/MarkedItemManager_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/MarkedItems/MarkedItemManager_Tests.cs @@ -18,13 +18,13 @@ public class MarkedItemManager_Tests : CmsKitDomainTestBase [Fact] public async Task ToggleAsync() { - var firstToggleResult = await _markedItemManager.ToggleAsync( + var firstToggleResult = await _markedItemManager.ToggleUserMarkedItemAsync( _cmsKitTestData.User1Id, _cmsKitTestData.EntityType2, _cmsKitTestData.EntityId1 ); - var secondToggleResult = await _markedItemManager.ToggleAsync( + var secondToggleResult = await _markedItemManager.ToggleUserMarkedItemAsync( _cmsKitTestData.User1Id, _cmsKitTestData.EntityType2, _cmsKitTestData.EntityId1 @@ -33,13 +33,4 @@ public class MarkedItemManager_Tests : CmsKitDomainTestBase firstToggleResult.ShouldBeTrue(); secondToggleResult.ShouldBeFalse(); } - - [Fact] - public async Task GetAsync() - { - var markedItem = await _markedItemManager.GetAsync(_cmsKitTestData.EntityType1); - - markedItem.EntityType.ShouldBe(_cmsKitTestData.EntityType1); - markedItem.IconName.ShouldBe(StandardMarkedItems.Favorite); - } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs index d4b055af60..b516c680a1 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -457,12 +457,12 @@ public class CmsKitDataSeedContributor : IDataSeedContributor, ITransientDepende private async Task SeedMarkedItemsAsync() { - await _markedItemManager.ToggleAsync( + await _markedItemManager.ToggleUserMarkedItemAsync( _cmsKitTestData.User1Id, _cmsKitTestData.EntityType1, _cmsKitTestData.EntityId1 ); - await _markedItemManager.ToggleAsync( + await _markedItemManager.ToggleUserMarkedItemAsync( _cmsKitTestData.User1Id, _cmsKitTestData.EntityType1, _cmsKitTestData.EntityId2 diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/MarkedItems/UserMarkedItemRepository_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/MarkedItems/UserMarkedItemRepository_Tests.cs index 5defd43029..f7af57f725 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/MarkedItems/UserMarkedItemRepository_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/MarkedItems/UserMarkedItemRepository_Tests.cs @@ -43,22 +43,15 @@ public abstract class UserMarkedItemRepository_Tests : CmsKitTes markedItems.Count.ShouldBe(2); } + [Fact] - public async Task GetQueryForUserAsync() + public async Task GetEntityIdsFilteredByUserAsync() { - await WithUnitOfWorkAsync(async () => - { - var query = await _userMarkedItemRepository.GetQueryForUserAsync( - _cmsKitTestData.EntityType1, - _cmsKitTestData.User1Id - ); - + var entityIds = await _userMarkedItemRepository.GetEntityIdsFilteredByUserAsync(_cmsKitTestData.User1Id, _cmsKitTestData.EntityType1); - var markedItems = query.ToList(); + entityIds.ShouldNotBeNull(); + entityIds.ShouldNotBeEmpty(); - markedItems.Count.ShouldBe(2); - markedItems.All(x => x.CreatorId == _cmsKitTestData.User1Id).ShouldBeTrue(); - markedItems.All(x => x.EntityType == _cmsKitTestData.EntityType1).ShouldBeTrue(); - }); + entityIds.Count.ShouldBe(2); } }