Added get comment to CommentAdminAppService

pull/7757/head
Ahmet 5 years ago
parent cb0afcbe27
commit 1843bae871

@ -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; }
}
}

@ -4,7 +4,7 @@ using Volo.CmsKit.Users;
namespace Volo.CmsKit.Admin.Comments
{
public class CommentWithDetailsDto
public class CommentWithAuthorDto
{
public Guid Id { get; set; }
@ -20,8 +20,6 @@ namespace Volo.CmsKit.Admin.Comments
public DateTime CreationTime { get; set; }
public List<CommentDto> Replies { get; set; }
public CmsUserDto Author { get; set; }
}
}

@ -1,4 +1,5 @@
using System.Linq.Dynamic.Core;
using System;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
@ -8,8 +9,8 @@ namespace Volo.CmsKit.Admin.Comments
{
Task<PagedResult<CommentDto>> GetListAsync(CommentGetListInput input);
Task<CommentWithDetailsDto> GetAsync(string entityType, string entityId);
Task<CommentWithAuthorDto> GetAsync(Guid id);
Task DeleteAsync(string entityType, string entityId);
Task DeleteAsync(Guid id);
}
}

@ -1,14 +1,18 @@
using AutoMapper;
using Volo.Abp.AutoMapper;
using Volo.CmsKit.Admin.Blogs;
using Volo.CmsKit.Admin.Comments;
using Volo.CmsKit.Admin.Contents;
using Volo.CmsKit.Admin.MediaDescriptors;
using Volo.CmsKit.Admin.Pages;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.Admin.Tags;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Contents;
using Volo.CmsKit.MediaDescriptors;
using Volo.CmsKit.Pages;
using Volo.CmsKit.Tags;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Admin
{
@ -16,6 +20,12 @@ namespace Volo.CmsKit.Admin
{
public CmsKitAdminApplicationAutoMapperProfile()
{
CreateMap<CmsUser, Comments.CmsUserDto>();
CreateMap<Comment, CommentDto>();
CreateMap<Comment, CommentWithAuthorDto>()
.Ignore(x=> x.Author);
CreateMap<Page, PageDto>();
CreateMap<Content, ContentDto>(MemberList.Destination);
@ -24,7 +34,6 @@ namespace Volo.CmsKit.Admin
CreateMap<ContentUpdateDto, Content>(MemberList.Source);
CreateMap<BlogPost, BlogPostDto>(MemberList.Destination);
CreateMap<CreateUpdateBlogPostDto, BlogPost>(MemberList.Source);
CreateMap<Blog, BlogDto>(MemberList.Destination)
.ReverseMap();

@ -0,0 +1,40 @@
using System;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.Admin.Comments
{
public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAppService
{
protected readonly ICommentRepository CommentRepository;
public CommentAdminAppService(ICommentRepository commentRepository)
{
CommentRepository = commentRepository;
}
public virtual Task<PagedResult<CommentDto>> GetListAsync(CommentGetListInput input)
{
throw new System.NotImplementedException();
}
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;
}
public virtual async Task DeleteAsync(Guid id)
{
var comment = await CommentRepository.GetAsync(id);
await CommentRepository.DeleteWithRepliesAsync(comment);
}
}
}

@ -9,6 +9,8 @@ namespace Volo.CmsKit.Comments
{
public interface ICommentRepository : IBasicRepository<Comment, Guid>
{
Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default);
Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
[NotNull] string entityType,
[NotNull] string entityId,

@ -5,6 +5,7 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.CmsKit.EntityFrameworkCore;
@ -20,6 +21,27 @@ namespace Volo.CmsKit.Comments
{
}
public async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default)
{
var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
where id == comment.Id
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (commentWithAuthor == null)
{
throw new EntityNotFoundException(typeof(Comment), id);
}
return commentWithAuthor;
}
public async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId,

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using MongoDB.Driver.Linq;
using MongoDB.Driver;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
using Volo.CmsKit.Comments;
@ -18,6 +19,27 @@ namespace Volo.CmsKit.MongoDB.Comments
{
}
public async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default)
{
var query = from comment in (await GetMongoQueryableAsync(cancellationToken))
join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id
where id == comment.Id
select new CommentWithAuthorQueryResultItem
{
Comment = comment,
Author = user
};
var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (commentWithAuthor == null)
{
throw new EntityNotFoundException(typeof(Comment), id);
}
return commentWithAuthor;
}
public async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId,

Loading…
Cancel
Save