mirror of https://github.com/abpframework/abp.git
33 changed files with 699 additions and 93 deletions
@ -0,0 +1,15 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Comments |
||||
|
{ |
||||
|
public class CmsUserDto |
||||
|
{ |
||||
|
public Guid Id { get; set; } |
||||
|
|
||||
|
public string UserName { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string Surname { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Comments |
||||
|
{ |
||||
|
public class CommentDto |
||||
|
{ |
||||
|
public Guid Id { get; set; } |
||||
|
|
||||
|
public string EntityType { get; set; } |
||||
|
|
||||
|
public string EntityId { get; set; } |
||||
|
|
||||
|
public string Text { get; set; } |
||||
|
|
||||
|
public Guid? RepliedCommentId { get; set; } |
||||
|
|
||||
|
public Guid CreatorId { get; set; } |
||||
|
|
||||
|
public DateTime CreationTime { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Comments |
||||
|
{ |
||||
|
public class CommentGetListInput : PagedAndSortedResultRequestDto |
||||
|
{ |
||||
|
public string EntityType { get; set; } |
||||
|
|
||||
|
public string EntityId { get; set; } |
||||
|
|
||||
|
public string Text { get; set; } |
||||
|
|
||||
|
public Guid? RepliedCommentId { get; set; } |
||||
|
|
||||
|
public string Author { get; set; } |
||||
|
|
||||
|
public DateTime? CreationStartDate { get; set; } |
||||
|
|
||||
|
public DateTime? CreationEndDate { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Volo.CmsKit.Users; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Comments |
||||
|
{ |
||||
|
public class CommentWithAuthorDto |
||||
|
{ |
||||
|
public Guid Id { get; set; } |
||||
|
|
||||
|
public string EntityType { get; set; } |
||||
|
|
||||
|
public string EntityId { get; set; } |
||||
|
|
||||
|
public string Text { get; set; } |
||||
|
|
||||
|
public Guid? RepliedCommentId { get; set; } |
||||
|
|
||||
|
public Guid CreatorId { get; set; } |
||||
|
|
||||
|
public DateTime CreationTime { get; set; } |
||||
|
|
||||
|
public CmsUserDto Author { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Comments |
||||
|
{ |
||||
|
public interface ICommentAdminAppService : IApplicationService |
||||
|
{ |
||||
|
Task<PagedResultDto<CommentWithAuthorDto>> GetListAsync(CommentGetListInput input); |
||||
|
|
||||
|
Task<CommentWithAuthorDto> GetAsync(Guid id); |
||||
|
|
||||
|
Task DeleteAsync(Guid id); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
using Volo.CmsKit.Comments; |
||||
|
using Volo.CmsKit.GlobalFeatures; |
||||
|
using Volo.CmsKit.Permissions; |
||||
|
using Volo.CmsKit.Users; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Comments |
||||
|
{ |
||||
|
[RequiresGlobalFeature(typeof(CommentsFeature))] |
||||
|
[Authorize(CmsKitAdminPermissions.Comments.Default)] |
||||
|
public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAppService |
||||
|
{ |
||||
|
protected ICommentRepository CommentRepository { get; } |
||||
|
|
||||
|
public CommentAdminAppService(ICommentRepository commentRepository) |
||||
|
{ |
||||
|
CommentRepository = commentRepository; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<PagedResultDto<CommentWithAuthorDto>> GetListAsync(CommentGetListInput input) |
||||
|
{ |
||||
|
var totalCount = await CommentRepository.GetCountAsync( |
||||
|
input.Text, |
||||
|
input.EntityType, |
||||
|
input.EntityId, |
||||
|
input.RepliedCommentId, |
||||
|
input.Author, |
||||
|
input.CreationStartDate, |
||||
|
input.CreationEndDate); |
||||
|
|
||||
|
var comments = await CommentRepository.GetListAsync( |
||||
|
input.Text, |
||||
|
input.EntityType, |
||||
|
input.EntityId, |
||||
|
input.RepliedCommentId, |
||||
|
input.Author, |
||||
|
input.CreationStartDate, |
||||
|
input.CreationEndDate, |
||||
|
input.Sorting, |
||||
|
input.MaxResultCount, |
||||
|
input.SkipCount |
||||
|
); |
||||
|
|
||||
|
var dtos = comments.Select(queryResultItem => |
||||
|
{ |
||||
|
var dto = ObjectMapper.Map<Comment, CommentWithAuthorDto>(queryResultItem.Comment); |
||||
|
dto.Author = ObjectMapper.Map<CmsUser, CmsUserDto>(queryResultItem.Author); |
||||
|
|
||||
|
return dto; |
||||
|
}).ToList(); |
||||
|
|
||||
|
return new PagedResultDto<CommentWithAuthorDto>(totalCount, dtos); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<CommentWithAuthorDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
var comment = await CommentRepository.GetWithAuthorAsync(id); |
||||
|
|
||||
|
var dto = ObjectMapper.Map<Comment, CommentWithAuthorDto>(comment.Comment); |
||||
|
dto.Author = ObjectMapper.Map<CmsUser, CmsUserDto>(comment.Author); |
||||
|
|
||||
|
return dto; |
||||
|
} |
||||
|
|
||||
|
[Authorize(CmsKitAdminPermissions.Comments.Delete)] |
||||
|
public virtual async Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
var comment = await CommentRepository.GetAsync(id); |
||||
|
await CommentRepository.DeleteWithRepliesAsync(comment); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
using Volo.CmsKit.GlobalFeatures; |
||||
|
using Volo.CmsKit.Permissions; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Comments |
||||
|
{ |
||||
|
[Authorize(CmsKitAdminPermissions.Comments.Default)] |
||||
|
[RequiresGlobalFeature(typeof(CommentsFeature))] |
||||
|
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] |
||||
|
[Area("cms-kit")] |
||||
|
[Route("api/cms-kit-admin/comments")] |
||||
|
public class CommentAdminController : CmsKitAdminController, ICommentAdminAppService |
||||
|
{ |
||||
|
protected ICommentAdminAppService CommentAdminAppService { get; } |
||||
|
|
||||
|
public CommentAdminController(ICommentAdminAppService commentAdminAppService) |
||||
|
{ |
||||
|
CommentAdminAppService = commentAdminAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
public virtual Task<PagedResultDto<CommentWithAuthorDto>> GetListAsync(CommentGetListInput input) |
||||
|
{ |
||||
|
return CommentAdminAppService.GetListAsync(input); |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("{id}")] |
||||
|
public virtual Task<CommentWithAuthorDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
return CommentAdminAppService.GetAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpDelete] |
||||
|
[Route("{id}")] |
||||
|
[Authorize(CmsKitAdminPermissions.Comments.Delete)] |
||||
|
public virtual Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
return CommentAdminAppService.DeleteAsync(id); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
using Volo.CmsKit.Admin.Comments; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.CmsKit.Comments |
||||
|
{ |
||||
|
public class CommentAdminAppService_Tests : CmsKitApplicationTestBase |
||||
|
{ |
||||
|
private readonly ICommentAdminAppService _commentAdminAppService; |
||||
|
private readonly CmsKitTestData _cmsKitTestData; |
||||
|
|
||||
|
public CommentAdminAppService_Tests() |
||||
|
{ |
||||
|
_commentAdminAppService = GetRequiredService<ICommentAdminAppService>(); |
||||
|
_cmsKitTestData = GetRequiredService<CmsKitTestData>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task ShouldGet_PagedListAsync() |
||||
|
{ |
||||
|
var comments = await _commentAdminAppService.GetListAsync(new CommentGetListInput |
||||
|
{ |
||||
|
MaxResultCount = 3 |
||||
|
}); |
||||
|
|
||||
|
comments.TotalCount.ShouldBe(6); |
||||
|
comments.Items.Count.ShouldBe(3); |
||||
|
comments.Items.Any(x => x.Author != null).ShouldBeTrue(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task ShouldGet_CommentWithAuthorAsync() |
||||
|
{ |
||||
|
var comment = await _commentAdminAppService.GetAsync(_cmsKitTestData.CommentWithChildId); |
||||
|
|
||||
|
comment.ShouldNotBeNull(); |
||||
|
comment.Author.ShouldNotBeNull(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task ShouldDelete_WithRepliesAsync() |
||||
|
{ |
||||
|
await _commentAdminAppService.DeleteAsync(_cmsKitTestData.CommentWithChildId); |
||||
|
|
||||
|
await Should.ThrowAsync<EntityNotFoundException>(async () => await _commentAdminAppService.GetAsync(_cmsKitTestData.CommentWithChildId)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue