From c96d364c39c3b701067eee399f2679af775e5822 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 21 Jan 2021 18:56:04 +0300 Subject: [PATCH 1/5] CmsKit - Content Get-Set endpoints --- .../Admin/Contents/ContentSetByEntityInput.cs | 7 +++ .../Admin/Contents/IContentAdminAppService.cs | 4 ++ .../Admin/Contents/ContentAdminAppService.cs | 45 ++++++++++++++++++- .../Admin/Contents/ContentAdminController.cs | 16 +++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs new file mode 100644 index 0000000000..744f708e45 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs @@ -0,0 +1,7 @@ +namespace Volo.CmsKit.Admin.Contents +{ + public class ContentSetByEntityInput + { + public string Value { get; set; } + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs index e910d42c2f..381498cbb1 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Volo.Abp.Application.Services; using Volo.CmsKit.Admin.Contents; @@ -13,5 +14,8 @@ namespace Volo.CmsKit.Admin.Contents ContentCreateDto, ContentUpdateDto> { + Task GetByEntityAsync(string entityType, string entityId); + + Task SetByEntityAsync(string entityType, string entityId, ContentSetByEntityInput input); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs index 5c058b5fe8..8c5b161540 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs @@ -1,6 +1,8 @@ -using Microsoft.AspNetCore.Authorization; +using JetBrains.Annotations; +using Microsoft.AspNetCore.Authorization; using System; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.CmsKit.Contents; @@ -31,13 +33,13 @@ namespace Volo.CmsKit.Admin.Contents IContentRepository contentRepository) : base(repository) { ContentManager = contentManager; + ContentRepository = contentRepository; GetListPolicyName = CmsKitAdminPermissions.Contents.Default; GetPolicyName = CmsKitAdminPermissions.Contents.Default; CreatePolicyName = CmsKitAdminPermissions.Contents.Create; UpdatePolicyName = CmsKitAdminPermissions.Contents.Update; DeletePolicyName = CmsKitAdminPermissions.Contents.Delete; - ContentRepository = contentRepository; } [Authorize(CmsKitAdminPermissions.Contents.Create)] @@ -54,5 +56,44 @@ namespace Volo.CmsKit.Admin.Contents return MapToGetOutputDto(entity); } + + public async Task GetByEntityAsync( + [NotNull] string entityType, + [NotNull] string entityId) + { + Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); + Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); + + var content = await ContentRepository.GetAsync(entityType, entityId, CurrentTenant?.Id); + + return ObjectMapper.Map(content); + } + + public async Task SetByEntityAsync( + [NotNull] string entityType, + [NotNull] string entityId, + ContentSetByEntityInput input) + { + Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); + Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); + + var updated = await ContentRepository.FindAsync(entityType, entityId); + + if (updated == null) + { + await ContentRepository.InsertAsync( + new Content( + GuidGenerator.Create(), + entityType, + entityId, + input.Value, + CurrentTenant?.Id)); + } + else + { + updated.SetValue(input.Value); + await ContentRepository.UpdateAsync(updated); + } + } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs index f519109022..0679391a4f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs @@ -59,5 +59,21 @@ namespace Volo.CmsKit.Admin.Contents { return ContentAdminAppService.UpdateAsync(id, input); } + + [HttpGet] + [Route("{entityType}/{entityId}")] + [Authorize(CmsKitAdminPermissions.Contents.Default)] + public Task GetByEntityAsync(string entityType, string entityId) + { + return ContentAdminAppService.GetByEntityAsync(entityType, entityId); + } + + [HttpPost] + [Route("{entityType}/{entityId}")] + [Authorize(CmsKitAdminPermissions.Contents.Update)] + public Task SetByEntityAsync(string entityType, string entityId, ContentSetByEntityInput input) + { + return ContentAdminAppService.SetByEntityAsync(entityType, entityId, input); + } } } From 15ba1bdfb556e0943cae9b5942ebe16047a5d98a Mon Sep 17 00:00:00 2001 From: enisn Date: Fri, 22 Jan 2021 10:47:49 +0300 Subject: [PATCH 2/5] CmsKit - Remove SetContentByEntity --- .../Admin/Contents/IContentAdminAppService.cs | 2 -- .../Admin/Contents/ContentAdminAppService.cs | 27 ------------------- .../Admin/Contents/ContentAdminController.cs | 8 ------ 3 files changed, 37 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs index 381498cbb1..fb5bf48349 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs @@ -15,7 +15,5 @@ namespace Volo.CmsKit.Admin.Contents ContentUpdateDto> { Task GetByEntityAsync(string entityType, string entityId); - - Task SetByEntityAsync(string entityType, string entityId, ContentSetByEntityInput input); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs index 8c5b161540..b1008f0086 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs @@ -68,32 +68,5 @@ namespace Volo.CmsKit.Admin.Contents return ObjectMapper.Map(content); } - - public async Task SetByEntityAsync( - [NotNull] string entityType, - [NotNull] string entityId, - ContentSetByEntityInput input) - { - Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); - Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); - - var updated = await ContentRepository.FindAsync(entityType, entityId); - - if (updated == null) - { - await ContentRepository.InsertAsync( - new Content( - GuidGenerator.Create(), - entityType, - entityId, - input.Value, - CurrentTenant?.Id)); - } - else - { - updated.SetValue(input.Value); - await ContentRepository.UpdateAsync(updated); - } - } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs index 0679391a4f..fa766a5cfb 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs @@ -67,13 +67,5 @@ namespace Volo.CmsKit.Admin.Contents { return ContentAdminAppService.GetByEntityAsync(entityType, entityId); } - - [HttpPost] - [Route("{entityType}/{entityId}")] - [Authorize(CmsKitAdminPermissions.Contents.Update)] - public Task SetByEntityAsync(string entityType, string entityId, ContentSetByEntityInput input) - { - return ContentAdminAppService.SetByEntityAsync(entityType, entityId, input); - } } } From dcb780a5c9daa05e2efc69860be0e4525f88e3c8 Mon Sep 17 00:00:00 2001 From: enisn Date: Fri, 22 Jan 2021 11:22:13 +0300 Subject: [PATCH 3/5] CmsKit - Remove ContentSetByEntityInput.cs --- .../Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs deleted file mode 100644 index 744f708e45..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentSetByEntityInput.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.CmsKit.Admin.Contents -{ - public class ContentSetByEntityInput - { - public string Value { get; set; } - } -} From f3ee251880a6a7784db9bc5a829d0ebc1cc07be9 Mon Sep 17 00:00:00 2001 From: enisn Date: Fri, 22 Jan 2021 11:29:07 +0300 Subject: [PATCH 4/5] CmsKit - Add test for GetByEntityAsync --- .../Contents/ContentAdminAppService_Tests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs index 34c90cbf6e..1263014d83 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -128,5 +128,15 @@ namespace Volo.CmsKit.Contents await Should.NotThrowAsync(async () => await _service.DeleteAsync(_data.Content_2_Id)); } + + [Fact] + public async Task ShouldGetByEntityAsync() + { + var entity = await _service.GetByEntityAsync(_data.Content_1_EntityType, _data.Content_1_EntityId); + + entity.ShouldNotBeNull(); + entity.EntityId.ShouldBe(_data.Content_1_EntityId); + entity.EntityType.ShouldBe(_data.Content_1_EntityType); + } } } From 3e8f0fdf5dc6198042632391ec307a89f5e4914b Mon Sep 17 00:00:00 2001 From: enisn Date: Fri, 22 Jan 2021 14:56:12 +0300 Subject: [PATCH 5/5] CmsKit - Refactor ContentAdminController --- .../Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs | 2 +- .../Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs | 2 +- .../Volo/CmsKit/Admin/Contents/ContentAdminController.cs | 4 ++-- .../Contents/ContentAdminAppService_Tests.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs index fb5bf48349..52bd07aa86 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs @@ -14,6 +14,6 @@ namespace Volo.CmsKit.Admin.Contents ContentCreateDto, ContentUpdateDto> { - Task GetByEntityAsync(string entityType, string entityId); + Task GetAsync(string entityType, string entityId); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs index b1008f0086..300cf31181 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs @@ -57,7 +57,7 @@ namespace Volo.CmsKit.Admin.Contents return MapToGetOutputDto(entity); } - public async Task GetByEntityAsync( + public async Task GetAsync( [NotNull] string entityType, [NotNull] string entityId) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs index fa766a5cfb..4e3a56a8e2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs @@ -63,9 +63,9 @@ namespace Volo.CmsKit.Admin.Contents [HttpGet] [Route("{entityType}/{entityId}")] [Authorize(CmsKitAdminPermissions.Contents.Default)] - public Task GetByEntityAsync(string entityType, string entityId) + public Task GetAsync(string entityType, string entityId) { - return ContentAdminAppService.GetByEntityAsync(entityType, entityId); + return ContentAdminAppService.GetAsync(entityType, entityId); } } } diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs index 1263014d83..5c7e5969f1 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -132,7 +132,7 @@ namespace Volo.CmsKit.Contents [Fact] public async Task ShouldGetByEntityAsync() { - var entity = await _service.GetByEntityAsync(_data.Content_1_EntityType, _data.Content_1_EntityId); + var entity = await _service.GetAsync(_data.Content_1_EntityType, _data.Content_1_EntityId); entity.ShouldNotBeNull(); entity.EntityId.ShouldBe(_data.Content_1_EntityId);