mirror of https://github.com/abpframework/abp.git
35 changed files with 2 additions and 1012 deletions
@ -1,71 +0,0 @@ |
|||
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; |
|||
using Volo.CmsKit.Permissions; |
|||
|
|||
namespace Volo.CmsKit.Admin.Contents |
|||
{ |
|||
[Authorize(CmsKitAdminPermissions.Contents.Default)] |
|||
public class ContentAdminAppService : |
|||
CrudAppService< |
|||
Content, |
|||
ContentDto, |
|||
ContentGetListDto, |
|||
Guid, |
|||
ContentGetListInput, |
|||
ContentCreateDto, |
|||
ContentUpdateDto |
|||
>, IContentAdminAppService |
|||
{ |
|||
protected IContentManager ContentManager { get; } |
|||
|
|||
protected IContentRepository ContentRepository { get; } |
|||
|
|||
public ContentAdminAppService( |
|||
IRepository<Content, Guid> repository, |
|||
IContentManager contentManager, |
|||
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; |
|||
} |
|||
|
|||
[Authorize(CmsKitAdminPermissions.Contents.Create)] |
|||
public override async Task<ContentDto> CreateAsync(ContentCreateDto input) |
|||
{ |
|||
var entity = new Content( |
|||
GuidGenerator.Create(), |
|||
input.EntityType, |
|||
input.EntityId, |
|||
input.Value, |
|||
CurrentTenant?.Id); |
|||
|
|||
await ContentManager.InsertAsync(entity); |
|||
|
|||
return await MapToGetOutputDtoAsync(entity); |
|||
} |
|||
|
|||
public virtual async Task<ContentDto> GetAsync( |
|||
[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, ContentDto>(content); |
|||
} |
|||
} |
|||
} |
|||
@ -1,44 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.ViewFeatures; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Packages.TuiEditor; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Packages.Uppy; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
|||
|
|||
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents.Components.ContentEditor |
|||
{ |
|||
[Widget( |
|||
StyleTypes = new[] |
|||
{ |
|||
typeof(TuiEditorStyleContributor) |
|||
}, |
|||
ScriptTypes = new[] |
|||
{ |
|||
typeof(TuiEditorScriptContributor), |
|||
typeof(UppyScriptContributor) |
|||
}, |
|||
ScriptFiles = new[] |
|||
{ |
|||
"/Pages/CmsKit/Contents/Components/ContentEditor/default.js" |
|||
})] |
|||
public class ContentEditorViewComponent : AbpViewComponent |
|||
{ |
|||
public async Task<IViewComponentResult> InvokeAsync(string inputId) |
|||
{ |
|||
return View( |
|||
"~/Pages/CmsKit/Contents/Components/ContentEditor/Default.cshtml", |
|||
new ContentEditorViewModel(inputId)); |
|||
} |
|||
|
|||
public class ContentEditorViewModel |
|||
{ |
|||
public ContentEditorViewModel(string inputId) |
|||
{ |
|||
InputId = inputId; |
|||
} |
|||
|
|||
public string InputId { get; set; } |
|||
} |
|||
} |
|||
} |
|||
@ -1,7 +0,0 @@ |
|||
@using System.Globalization |
|||
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents.Components.ContentEditor |
|||
|
|||
@model ContentEditorViewComponent.ContentEditorViewModel |
|||
|
|||
<div class="content-editor" id="@Model.InputId-container" data-input-id="@Model.InputId" data-language="@(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName)"> |
|||
</div> |
|||
@ -1,80 +0,0 @@ |
|||
$(function () { |
|||
var fileUploadUri = "/api/cms-kit-admin/media"; |
|||
var fileUriPrefix = "/api/cms-kit/media/"; |
|||
|
|||
var editorDataKey = "tuiEditor"; |
|||
|
|||
initAllEditors(); |
|||
|
|||
function initAllEditors() { |
|||
$('.content-editor').each(function (i, item) { |
|||
initEditor(item); |
|||
}); |
|||
} |
|||
|
|||
function initEditor(element) { |
|||
var $editorContainer = $(element); |
|||
var inputName = $editorContainer.data('input-id'); |
|||
var $editorInput = $('#' + inputName); |
|||
var initialValue = $editorInput.val(); |
|||
|
|||
var editor = $editorContainer.tuiEditor({ |
|||
usageStatistics: false, |
|||
useCommandShortcut: true, |
|||
initialValue: initialValue, |
|||
previewStyle: 'tab', |
|||
height: "25em", |
|||
minHeight: "25em", |
|||
initialEditType: initialValue ? 'wysiwyg' : 'markdown', |
|||
language: $editorContainer.data("language"), |
|||
hooks: { |
|||
addImageBlobHook: uploadFile, |
|||
}, |
|||
events: { |
|||
change: function (_val) { |
|||
$editorInput.val(editor.getHtml()); |
|||
$editorInput.trigger("change"); |
|||
} |
|||
} |
|||
}).data(editorDataKey); |
|||
} |
|||
|
|||
function getUppyHeaders() { |
|||
var headers = {}; |
|||
headers[abp.security.antiForgery.tokenHeaderName] = abp.security.antiForgery.getToken(); |
|||
|
|||
return headers; |
|||
} |
|||
|
|||
function uploadFile(blob, callback, source) { |
|||
var UPPY_OPTIONS = { |
|||
endpoint: fileUploadUri, |
|||
formData: true, |
|||
fieldName: "file", |
|||
method: "post", |
|||
headers: getUppyHeaders() |
|||
}; |
|||
|
|||
var UPPY = Uppy.Core().use(Uppy.XHRUpload, UPPY_OPTIONS); |
|||
|
|||
UPPY.reset(); |
|||
|
|||
UPPY.addFile({ |
|||
id: "content-file", |
|||
name: blob.name, |
|||
type: blob.type, |
|||
data: blob, |
|||
}); |
|||
|
|||
UPPY.upload().then((result) => { |
|||
if (result.failed.length > 0) { |
|||
abp.message.error("File upload failed"); |
|||
} else { |
|||
var mediaDto = result.successful[0].response.body; |
|||
var fileUrl = (fileUriPrefix + mediaDto.id); |
|||
|
|||
callback(fileUrl, mediaDto.name); |
|||
} |
|||
}); |
|||
} |
|||
}); |
|||
@ -1,28 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
|
|||
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents.Components.EntityContentEditor |
|||
{ |
|||
public class ContentViewModel |
|||
{ |
|||
public ContentViewModel(string entityType, string entityId, string value = null, Guid? id = null) |
|||
{ |
|||
EntityType = entityType; |
|||
EntityId = entityId; |
|||
Value = value; |
|||
Id = id; |
|||
} |
|||
|
|||
[HiddenInput] |
|||
public string EntityType { get; set; } |
|||
|
|||
[HiddenInput] |
|||
public string EntityId { get; set; } |
|||
|
|||
[HiddenInput] |
|||
public string Value { get; set; } |
|||
|
|||
[HiddenInput] |
|||
public Guid? Id { get; set; } |
|||
} |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents.Components.EntityContentEditor |
|||
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents.Components.ContentEditor |
|||
@using Volo.CmsKit.Localization |
|||
@using Microsoft.Extensions.Localization |
|||
|
|||
@model EntityContentEditorViewComponent.EntityContentEditorViewModel |
|||
|
|||
@inject IStringLocalizer<CmsKitResource> L |
|||
|
|||
@if (Model.DisplaySubmitButton) |
|||
{ |
|||
<abp-dynamic-form abp-model="ViewModel" class="form-entity-content-editor"> |
|||
|
|||
<abp-form-content /> |
|||
|
|||
<abp-button button-type="Primary" type="submit" text="@L["Submit"]" /> |
|||
</abp-dynamic-form> |
|||
} |
|||
else |
|||
{ |
|||
<abp-input asp-for="ViewModel.Id" /> |
|||
<abp-input asp-for="ViewModel.EntityId" /> |
|||
<abp-input asp-for="ViewModel.EntityType" /> |
|||
<abp-input asp-for="ViewModel.Value" /> |
|||
} |
|||
|
|||
@await Component.InvokeAsync(typeof(ContentEditorViewComponent), new { inputId = Html.IdFor(m => m.ViewModel.Value) }) |
|||
@ -1,65 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.CmsKit.Admin.Contents; |
|||
|
|||
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents.Components.EntityContentEditor |
|||
{ |
|||
[Widget( |
|||
ScriptFiles = new[] |
|||
{ |
|||
"/Pages/CmsKit/Contents/Components/EntityContentEditor/default.js" |
|||
})] |
|||
public class EntityContentEditorViewComponent : AbpViewComponent |
|||
{ |
|||
private readonly IContentAdminAppService contentAdminAppService; |
|||
|
|||
public EntityContentEditorViewComponent(IContentAdminAppService contentAdminAppService) |
|||
{ |
|||
this.contentAdminAppService = contentAdminAppService; |
|||
} |
|||
|
|||
public async Task<IViewComponentResult> InvokeAsync(string entityType, string entityId, bool displaySubmitButton = true) |
|||
{ |
|||
var viewModel = new ContentViewModel(entityType, entityId); |
|||
|
|||
try |
|||
{ |
|||
if (entityId != null) |
|||
{ |
|||
var content = await contentAdminAppService.GetAsync(entityType, entityId); |
|||
viewModel.Value = content.Value; |
|||
viewModel.Id = content.Id; |
|||
} |
|||
} |
|||
catch (EntityNotFoundException) |
|||
{ |
|||
// Initialize editor even content doesn't exist.
|
|||
} |
|||
|
|||
return View( |
|||
"~/Pages/CmsKit/Contents/Components/EntityContentEditor/Default.cshtml", |
|||
new EntityContentEditorViewModel(viewModel, displaySubmitButton)); |
|||
} |
|||
|
|||
public class EntityContentEditorViewModel |
|||
{ |
|||
public ContentViewModel ViewModel { get; set; } |
|||
|
|||
public bool DisplaySubmitButton { get; set; } |
|||
|
|||
public EntityContentEditorViewModel(ContentViewModel viewModel, bool displaySubmitButton) |
|||
{ |
|||
ViewModel = viewModel; |
|||
DisplaySubmitButton = displaySubmitButton; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
$(function () { |
|||
|
|||
$entityContentEditors = $('.form-entity-content-editor'); |
|||
|
|||
var contentAdminService = volo.cmsKit.admin.contents.contentAdmin; |
|||
|
|||
$entityContentEditors.on('submit', function (e, obj) { |
|||
e.preventDefault(); |
|||
|
|||
var $form = $(e.currentTarget); |
|||
|
|||
if ($form.valid()) { |
|||
|
|||
var data = form.serializeFormToObject().viewModel; |
|||
|
|||
abp.ui.setBusy(e); |
|||
if (data.id) { |
|||
contentAdminService |
|||
.update(data.id, data) |
|||
.then(function (result) { |
|||
abp.ui.clearBusy(); |
|||
}); |
|||
|
|||
} |
|||
else { |
|||
contentAdminService |
|||
.create(data) |
|||
.then(function (result) { |
|||
abp.ui.clearBusy(); |
|||
}); |
|||
} |
|||
} |
|||
}) |
|||
}) |
|||
@ -1,44 +0,0 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public class Content : FullAuditedAggregateRoot<Guid>, IMultiTenant |
|||
{ |
|||
[CanBeNull] public virtual Guid? TenantId { get; protected set; } |
|||
|
|||
[NotNull] public virtual string EntityType { get; protected set; } |
|||
|
|||
[NotNull] public virtual string EntityId { get; protected set; } |
|||
|
|||
[NotNull] public virtual string Value { get; protected set; } |
|||
|
|||
protected Content() |
|||
{ |
|||
} |
|||
|
|||
public Content(Guid id, [NotNull] string entityType, [NotNull] string entityId, [NotNull] string value, |
|||
Guid? tenantId = null) : base(id) |
|||
{ |
|||
EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength); |
|||
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength); |
|||
Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength); |
|||
|
|||
TenantId = tenantId; |
|||
} |
|||
|
|||
public virtual void SetValue([NotNull] string value) |
|||
{ |
|||
Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength); |
|||
} |
|||
|
|||
public virtual void SetEntity([NotNull] string entityType, [NotNull] string entityId) |
|||
{ |
|||
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength); |
|||
EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength); |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
[Serializable] |
|||
public class ContentAlreadyExistException : BusinessException |
|||
{ |
|||
public ContentAlreadyExistException([NotNull] string entityType, [NotNull] string entityId) |
|||
{ |
|||
Code = CmsKitErrorCodes.ContentAlreadyExist; |
|||
WithData(nameof(Content.EntityType), entityType); |
|||
WithData(nameof(Content.EntityId), entityId); |
|||
} |
|||
} |
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public class ContentManager : DomainService, IContentManager |
|||
{ |
|||
protected IContentRepository ContentRepository { get; } |
|||
|
|||
public ContentManager(IContentRepository contentRepository) |
|||
{ |
|||
ContentRepository = contentRepository; |
|||
} |
|||
|
|||
public virtual async Task<Content> InsertAsync(Content content, CancellationToken cancellationToken = default) |
|||
{ |
|||
if (await ContentRepository.ExistsAsync(content.EntityType, content.EntityId, content.TenantId, |
|||
cancellationToken)) |
|||
{ |
|||
throw new ContentAlreadyExistException(content.EntityType, content.EntityId); |
|||
} |
|||
|
|||
return await ContentRepository.InsertAsync(content, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public interface IContentManager |
|||
{ |
|||
Task<Content> InsertAsync(Content content, CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public interface IContentRepository : IBasicRepository<Content, Guid> |
|||
{ |
|||
Task<Content> GetAsync( |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<Content> FindAsync( |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteAsync( |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<bool> ExistsAsync( |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
@ -1,86 +0,0 @@ |
|||
using JetBrains.Annotations; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.CmsKit.EntityFrameworkCore; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public class EfCoreContentRepository : EfCoreRepository<ICmsKitDbContext, Content, Guid>, IContentRepository |
|||
{ |
|||
public EfCoreContentRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual Task<Content> GetAsync( |
|||
string entityType, |
|||
string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(entityId, nameof(entityId)); |
|||
|
|||
return GetAsync(x => |
|||
x.EntityType == entityType && |
|||
x.EntityId == entityId && |
|||
x.TenantId == tenantId, |
|||
cancellationToken: GetCancellationToken(cancellationToken) |
|||
); |
|||
} |
|||
|
|||
public virtual Task<Content> FindAsync( |
|||
string entityType, |
|||
string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(entityId, nameof(entityId)); |
|||
|
|||
return FindAsync(x => |
|||
x.EntityType == entityType && |
|||
x.EntityId == entityId && |
|||
x.TenantId == tenantId, |
|||
cancellationToken: GetCancellationToken(cancellationToken) |
|||
); |
|||
} |
|||
|
|||
public virtual Task DeleteAsync( |
|||
string entityType, |
|||
string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(entityId, nameof(entityId)); |
|||
|
|||
return DeleteAsync(x => |
|||
x.EntityType == entityType && |
|||
x.EntityId == entityId && |
|||
x.TenantId == tenantId, |
|||
cancellationToken: GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> ExistsAsync( |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(entityId, nameof(entityId)); |
|||
|
|||
var dbSet = await GetDbSetAsync(); |
|||
return await dbSet.AnyAsync(x => |
|||
x.EntityType == entityType && |
|||
x.EntityId == entityId && |
|||
x.TenantId == tenantId, |
|||
cancellationToken: GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,80 +0,0 @@ |
|||
using JetBrains.Annotations; |
|||
using MongoDB.Driver.Linq; |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.MongoDB.Contents |
|||
{ |
|||
public class MongoContentRepository : MongoDbRepository<ICmsKitMongoDbContext, Content, Guid>, IContentRepository |
|||
{ |
|||
public MongoContentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base( |
|||
dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual Task<Content> GetAsync( |
|||
string entityType, |
|||
string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(entityId, nameof(entityId)); |
|||
|
|||
return GetAsync(x => |
|||
x.EntityType == entityType && |
|||
x.EntityId == entityId && |
|||
x.TenantId == tenantId, |
|||
cancellationToken: GetCancellationToken(cancellationToken) |
|||
); |
|||
} |
|||
|
|||
public virtual Task<Content> FindAsync( |
|||
string entityType, |
|||
string entityId, |
|||
Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(entityId, nameof(entityId)); |
|||
|
|||
return FindAsync(x => |
|||
x.EntityType == entityType && |
|||
x.EntityId == entityId && |
|||
x.TenantId == tenantId, |
|||
cancellationToken: GetCancellationToken(cancellationToken) |
|||
); |
|||
} |
|||
|
|||
public virtual Task DeleteAsync(string entityType, string entityId, Guid? tenantId = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(entityId, nameof(entityId)); |
|||
|
|||
return DeleteAsync(x => |
|||
x.EntityType == entityType && |
|||
x.EntityId == entityId && |
|||
x.TenantId == tenantId, |
|||
cancellationToken: GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> ExistsAsync([NotNull] string entityType, [NotNull] string entityId, |
|||
Guid? tenantId = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
Check.NotNullOrEmpty(entityType, nameof(entityType)); |
|||
Check.NotNullOrEmpty(entityId, nameof(entityId)); |
|||
|
|||
return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => |
|||
x.EntityType == entityType && |
|||
x.EntityId == entityId && |
|||
x.TenantId == tenantId, |
|||
cancellationToken: GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Public.Contents |
|||
{ |
|||
public class ContentPublicAppService : CmsKitPublicAppServiceBase, IContentPublicAppService |
|||
{ |
|||
protected IContentRepository ContentRepository { get; } |
|||
|
|||
public ContentPublicAppService(IContentRepository contentRepository) |
|||
{ |
|||
ContentRepository = contentRepository; |
|||
} |
|||
|
|||
public virtual async Task<ContentDto> GetAsync(GetContentInput input) |
|||
{ |
|||
var entity = await ContentRepository.GetAsync( |
|||
input.EntityType, |
|||
input.EntityId, |
|||
CurrentTenant.Id); |
|||
|
|||
return ObjectMapper.Map<Content, ContentDto>(entity); |
|||
} |
|||
} |
|||
} |
|||
@ -1,142 +0,0 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using NSubstitute; |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Users; |
|||
using Volo.CmsKit.Admin.Contents; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public class ContentAdminAppService_Tests : CmsKitApplicationTestBase |
|||
{ |
|||
private ICurrentUser _currentUser; |
|||
private readonly CmsKitTestData _data; |
|||
private readonly IContentAdminAppService _service; |
|||
public ContentAdminAppService_Tests() |
|||
{ |
|||
_data = GetRequiredService<CmsKitTestData>(); |
|||
_service = GetRequiredService<IContentAdminAppService>(); |
|||
} |
|||
|
|||
protected override void AfterAddApplication(IServiceCollection services) |
|||
{ |
|||
_currentUser = Substitute.For<ICurrentUser>(); |
|||
services.AddSingleton(_currentUser); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldGetListAsync() |
|||
{ |
|||
var result = await _service.GetListAsync(new ContentGetListInput()); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
result.Items.ShouldNotBeEmpty(); |
|||
result.Items.Count.ShouldBe(4); |
|||
result.Items.All(x => x.ShouldBeOfType<ContentGetListDto>() != null); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldGetAsync() |
|||
{ |
|||
var result = await _service.GetAsync(_data.Content_1_Id); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
result.ShouldBeOfType<Admin.Contents.ContentDto>(); |
|||
result.ShouldNotBeNull(result.Value); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldCreateAsync() |
|||
{ |
|||
var entityId = "1-2-3"; |
|||
var entityType = "My.Awesome.Blog"; |
|||
var value = "Some long content"; |
|||
|
|||
var created = await _service.CreateAsync(new ContentCreateDto |
|||
{ |
|||
EntityId = entityId, |
|||
EntityType = entityType, |
|||
Value = value |
|||
}); |
|||
|
|||
created.Id.ShouldNotBe(Guid.Empty); |
|||
|
|||
var content = await _service.GetAsync(created.Id); |
|||
|
|||
content.ShouldNotBeNull(); |
|||
content.EntityType.ShouldBe(entityType); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotCreateWithSameParametersAsync() |
|||
{ |
|||
var entityTtype = "My.Awesome.Book"; |
|||
var entityId = "1"; |
|||
|
|||
await _service.CreateAsync(new ContentCreateDto |
|||
{ |
|||
EntityId = entityId, |
|||
EntityType = entityTtype, |
|||
Value = "Some long content" |
|||
}); |
|||
|
|||
await Should.ThrowAsync<ContentAlreadyExistException>(async () => |
|||
await _service.CreateAsync(new ContentCreateDto |
|||
{ |
|||
EntityId = entityId, |
|||
EntityType = entityTtype, |
|||
Value = "Yet another long content" |
|||
}) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldUpdateAsync() |
|||
{ |
|||
string newValue = "Newly created fresh value"; |
|||
var updateDto = new ContentUpdateDto |
|||
{ |
|||
Value = newValue |
|||
}; |
|||
|
|||
await _service.UpdateAsync(_data.Content_1_Id, updateDto); |
|||
|
|||
var content = await _service.GetAsync(_data.Content_1_Id); |
|||
content.ShouldNotBeNull(); |
|||
content.Value.ShouldBe(newValue); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldDeleteAsync() |
|||
{ |
|||
await _service.DeleteAsync(_data.Content_2_Id); |
|||
|
|||
await Should.ThrowAsync<EntityNotFoundException>(async () => await _service.GetAsync(_data.Content_2_Id)); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotThrowEntityNotFoundExceptionWhileDeletingAlreadyDeletedAsync() |
|||
{ |
|||
await _service.DeleteAsync(_data.Content_2_Id); |
|||
|
|||
await Should.NotThrowAsync(async () => |
|||
await _service.DeleteAsync(_data.Content_2_Id)); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldGetByEntityAsync() |
|||
{ |
|||
var entity = await _service.GetAsync(_data.Content_1_EntityType, _data.Content_1_EntityId); |
|||
|
|||
entity.ShouldNotBeNull(); |
|||
entity.EntityId.ShouldBe(_data.Content_1_EntityId); |
|||
entity.EntityType.ShouldBe(_data.Content_1_EntityType); |
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.EntityFrameworkCore.Contents |
|||
{ |
|||
public class ContentRepository_Test : ContentRepository_Tests<CmsKitEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
using Volo.CmsKit.Contents; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.MongoDB.Contents |
|||
{ |
|||
[Collection(MongoTestCollection.Name)] |
|||
public class ContentRepository_Test : ContentRepository_Tests<CmsKitMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,63 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public abstract class ContentRepository_Tests<TStartupModule> : CmsKitTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly CmsKitTestData _cmsKitTestData; |
|||
private readonly IContentRepository _contentRepository; |
|||
|
|||
protected ContentRepository_Tests() |
|||
{ |
|||
_cmsKitTestData = GetRequiredService<CmsKitTestData>(); |
|||
_contentRepository = GetRequiredService<IContentRepository>(); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData("Lyrics", "1", "First things first")] |
|||
[InlineData("LyricsAlso", "2", "Second thing second")] |
|||
public async Task ShouldGetAsync(string entityType, string entityId, string contentStartsWith = null) |
|||
{ |
|||
var content = await _contentRepository.GetAsync(entityType, entityId); |
|||
|
|||
content.ShouldNotBeNull(); |
|||
|
|||
if (contentStartsWith != null) |
|||
{ |
|||
content.Value.ShouldStartWith(contentStartsWith); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotGetAsync() |
|||
{ |
|||
Should.Throw<EntityNotFoundException>( |
|||
async () |
|||
=> |
|||
await _contentRepository.GetAsync("not_exist_entity", Guid.NewGuid().ToString())); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldFindAsync() |
|||
{ |
|||
var content = |
|||
await _contentRepository.FindAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_EntityId); |
|||
|
|||
content.ShouldNotBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotFindAsync() |
|||
{ |
|||
var content = await _contentRepository.FindAsync("not_exist_entity", Guid.NewGuid().ToString()); |
|||
|
|||
content.ShouldBeNull(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue