Browse Source

a new method has been written for recent posts

pull/16503/head
Onur Pıçakcı 3 years ago
parent
commit
01a00589e8
  1. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs
  2. 29
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  3. 2
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs
  4. 14
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUser.cs
  5. 9
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs
  6. 9
      modules/blogging/src/Volo.Blogging.HttpApi.Client/ClientProxies/PostsClientProxy.Generated.cs
  7. 7
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs
  8. 10
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs
  9. 4
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml
  10. 2
      modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml.cs
  11. 2
      modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.js

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs

@ -23,5 +23,7 @@ namespace Volo.Blogging.Posts
Task<PostWithDetailsDto> UpdateAsync(Guid id, UpdatePostDto input);
Task<List<PostWithDetailsDto>> GetListByUserIdAsync(Guid userId);
Task<List<PostWithDetailsDto>> GetLatestBlogPostsAsync(Guid blogId, int count);
}
}

29
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

@ -195,6 +195,35 @@ namespace Volo.Blogging.Posts
return ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts);
}
public async Task<List<PostWithDetailsDto>> GetLatestBlogPostsAsync(Guid blogId, int count)
{
var posts = await PostRepository.GetLatestBlogPostsAsync(blogId, count);
var userDictionary = new Dictionary<Guid, BlogUserDto>();
var postDtos = new List<PostWithDetailsDto>(ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts));
foreach (var postDto in postDtos)
{
if (postDto.CreatorId.HasValue)
{
if (!userDictionary.ContainsKey(postDto.CreatorId.Value))
{
var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value);
if (creatorUser != null)
{
userDictionary[creatorUser.Id] = ObjectMapper.Map<BlogUser, BlogUserDto>(creatorUser);
}
}
if (userDictionary.ContainsKey(postDto.CreatorId.Value))
{
postDto.Writer = userDictionary[(Guid)postDto.CreatorId];
}
}
}
return new List<PostWithDetailsDto>(postDtos);
}
[Authorize(BloggingPermissions.Posts.Create)]
public async Task<PostWithDetailsDto> CreateAsync(CreatePostDto input)
{

2
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs

@ -17,5 +17,7 @@ namespace Volo.Blogging.Posts
Task<List<Post>> GetOrderedList(Guid blogId,bool descending = false, CancellationToken cancellationToken = default);
Task<List<Post>> GetListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default);
Task<List<Post>> GetLatestBlogPostsAsync(Guid blogId, int count, CancellationToken cancellationToken = default);
}
}

14
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUser.cs

@ -26,25 +26,25 @@ namespace Volo.Blogging.Users
public virtual bool PhoneNumberConfirmed { get; protected set; }
[CanBeNull]
public string WebSite { get; set; }
public virtual string WebSite { get; set; }
[CanBeNull]
public string Twitter { get; set; }
public virtual string Twitter { get; set; }
[CanBeNull]
public string Github { get; set; }
public virtual string Github { get; set; }
[CanBeNull]
public string Linkedin { get; set; }
public virtual string Linkedin { get; set; }
[CanBeNull]
public string Company { get; set; }
public virtual string Company { get; set; }
[CanBeNull]
public string JobTitle { get; set; }
public virtual string JobTitle { get; set; }
[CanBeNull]
public string Biography { get; set; }
public virtual string Biography { get; set; }
protected BlogUser()
{

9
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs

@ -70,6 +70,15 @@ namespace Volo.Blogging.Posts
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<Post>> GetLatestBlogPostsAsync(Guid blogId, int count, CancellationToken cancellationToken = default)
{
var query = (await GetDbSetAsync()).Where(p => p.BlogId == blogId)
.OrderByDescending(p => p.CreationTime)
.Take(count);
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public override async Task<IQueryable<Post>> WithDetailsAsync()
{
return (await GetQueryableAsync()).IncludeDetails();

9
modules/blogging/src/Volo.Blogging.HttpApi.Client/ClientProxies/PostsClientProxy.Generated.cs

@ -74,6 +74,15 @@ public partial class PostsClientProxy : ClientProxyBase<IPostAppService>, IPostA
});
}
public Task<List<PostWithDetailsDto>> GetLatestBlogPostsAsync(Guid blogId, int count)
{
return RequestAsync<List<PostWithDetailsDto>>(nameof(GetLatestBlogPostsAsync), new ClientProxyRequestTypeValue
{
{ typeof(Guid), blogId },
{ typeof(int), count }
});
}
public virtual async Task DeleteAsync(Guid id)
{
await RequestAsync(nameof(DeleteAsync), new ClientProxyRequestTypeValue

7
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs

@ -69,6 +69,13 @@ namespace Volo.Blogging
return _postAppService.GetListByUserIdAsync(userId);
}
[HttpGet]
[Route("{blogId}/latest/{count}")]
public Task<List<PostWithDetailsDto>> GetLatestBlogPostsAsync(Guid blogId, int count)
{
return _postAppService.GetLatestBlogPostsAsync(blogId, count);
}
[HttpDelete]
[Route("{id}")]
public Task DeleteAsync(Guid id)

10
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs

@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Nito.AsyncEx;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
@ -66,5 +67,14 @@ namespace Volo.Blogging.Posts
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<Post>> GetLatestBlogPostsAsync(Guid blogId, int count, CancellationToken cancellationToken = default)
{
var query = (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.BlogId == blogId)
.OrderByDescending(x => x.CreationTime)
.Take(count);
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
}
}

4
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml

@ -439,12 +439,12 @@
}
else
{
<a abp-button="Primary" class="btn-rounded float-end active mt-3" href="/Account/Login?returnUrl=@System.Web.HttpUtility.UrlEncode(@Request.Path)">@L["LeaveComment"]</a>
<a abp-button="Primary" class="btn-rounded float-end active" href="/Account/Login?returnUrl=@System.Web.HttpUtility.UrlEncode(@Request.Path)">@L["LeaveComment"]</a>
}
<div class="hero articles">
<div class="hero content">
<p class="fs-3 fw-bold text-dark">More from @CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Model.Post.Writer.UserName)</p>
@for (var index = 0; index < Model.PostsList.Count && index <= 5; index++)
@for (var index = 0; index < Model.PostsList.Count; index++)
{
if (Model.PostsList[index].Id != Model.Post.Id)
{

2
modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml.cs

@ -87,7 +87,7 @@ namespace Volo.Blogging.Pages.Blog.Posts
Blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetForReadingAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl });
PostsList = await _postAppService.GetListByUserIdAsync(Post.Writer.Id);
LatestPosts = (await _postAppService.GetListByBlogIdAndTagNameAsync(Blog.Id, TagName)).Items;
LatestPosts = await _postAppService.GetLatestBlogPostsAsync(Blog.Id, 5);
CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(Post.Id);
CountComments();
}

2
modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.js

@ -1,8 +1,6 @@
$(function () {
debugger
var hash = window.location.hash;
if(hash === '#edit-profile'){
console.log("asdasdsa")
$('#all-posts-tab').removeClass('active');
$('#all-posts').removeClass('show').removeClass('active');
$('#edit-profile-tab').addClass('active');

Loading…
Cancel
Save