diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Members/IMemberAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Members/IMemberAppService.cs new file mode 100644 index 0000000000..5e06d20956 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Members/IMemberAppService.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Blogging.Posts; + +namespace Volo.Blogging.Members; + +public interface IMemberAppService : IApplicationService +{ + Task FindAsync(string username); +} \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs index 8f1f2c251d..e4af45a345 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -20,5 +21,7 @@ namespace Volo.Blogging.Posts Task CreateAsync(CreatePostDto input); Task UpdateAsync(Guid id, UpdatePostDto input); + + Task> GetListByUserIdAsync(Guid userId); } } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Members/MemberAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Members/MemberAppService.cs new file mode 100644 index 0000000000..d22c2fae53 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Members/MemberAppService.cs @@ -0,0 +1,24 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; +using Volo.Blogging.Posts; +using Volo.Blogging.Users; + +namespace Volo.Blogging.Members; + +public class MemberAppService : BloggingAppServiceBase, IMemberAppService +{ + private readonly IRepository _userRepository; + + public MemberAppService(IRepository userRepository) + { + _userRepository = userRepository; + } + + public async Task FindAsync(string username) + { + var user = await _userRepository.FindAsync(x => x.UserName == username); + + return ObjectMapper.Map(user); + } +} \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index 15506ecf70..da2db68db4 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -188,6 +188,17 @@ namespace Volo.Blogging.Posts return ObjectMapper.Map(post); } + public async Task> GetListByUserIdAsync(Guid userId) + { + var posts = await PostRepository.GetListByUserIdAsync(userId); + + if (CurrentUser != null) + { + + } + return ObjectMapper.Map, List>(posts); + } + [Authorize(BloggingPermissions.Posts.Create)] public async Task CreateAsync(CreatePostDto input) { diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs index b5446515bf..33a6377264 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs @@ -15,5 +15,7 @@ namespace Volo.Blogging.Posts Task GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default); Task> GetOrderedList(Guid blogId,bool descending = false, CancellationToken cancellationToken = default); + + Task> GetListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default); } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs index a676816dee..34d835d447 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs @@ -8,6 +8,7 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Blogging.EntityFrameworkCore; +using Volo.Blogging.Users; namespace Volo.Blogging.Posts { @@ -61,6 +62,14 @@ namespace Volo.Blogging.Posts } + public async Task> GetListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default) + { + var query = (await GetDbSetAsync()).Where(p => p.CreatorId == userId) + .OrderBy(p => p.CreationTime); + + return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } + public override async Task> WithDetailsAsync() { return (await GetQueryableAsync()).IncludeDetails(); diff --git a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs index 03cd460ed2..f2f31261a6 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs +++ b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp; @@ -60,6 +61,13 @@ namespace Volo.Blogging { return _postAppService.UpdateAsync(id, input); } + + [HttpGet] + [Route("user/{userId}")] + public Task> GetListByUserIdAsync(Guid userId) + { + return _postAppService.GetListByUserIdAsync(userId); + } [HttpDelete] [Route("{id}")] diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs index a2d79c9466..7c64cd79e9 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs @@ -58,5 +58,13 @@ namespace Volo.Blogging.Posts return await query.OrderByDescending(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); } + + public async Task> GetListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default) + { + var query = (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.CreatorId == userId) + .OrderBy(x => x.CreationTime); + + return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs index 1391a5de19..dd8d65ea6b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs +++ b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs @@ -95,6 +95,7 @@ namespace Volo.Blogging options.Conventions.AddPageRoute("/Blogs/Posts/Detail", routePrefix + "{blogShortName:blogNameConstraint}/{postUrl}"); options.Conventions.AddPageRoute("/Blogs/Posts/Edit", routePrefix + "{blogShortName}/posts/{postId}/edit"); options.Conventions.AddPageRoute("/Blogs/Posts/New", routePrefix + "{blogShortName}/posts/new"); + options.Conventions.AddPageRoute("/Members/Index", routePrefix + "members/{userName}"); }); Configure(options => diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml new file mode 100644 index 0000000000..1084d2bd35 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml @@ -0,0 +1,86 @@ +@page +@using System.Text +@using Microsoft.Extensions.Localization +@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert +@using Volo.Abp.Users +@using Volo.Blogging.Localization +@model Volo.Blogging.Pages.Members.IndexModel +@inject IStringLocalizer L +@inject ICurrentUser CurrentUser + + + +
+
+
+
+
+
+ @if (Model.User.UserName == CurrentUser.UserName) + { +
+ +
+ } + else + { + + } + @if (Model.User.UserName != null) + { +

@Model.User.UserName

+ } + + @L["UserName"].Value.ToUpper() +
@Model.User.UserName
+
+
+
+
+ + +
+ @foreach (var post in Model.Posts) + { +
+
+ + + + +
+
+ + +

+ @if ((post.Title).Any()) + { + @foreach (var highlight in post.Title) + { + @Html.Raw(highlight) + } + } + else + { + @post.Title + } +

+
+
+ +
+
+ } +
+
+
+
+
+
+
\ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml.cs new file mode 100644 index 0000000000..13881fb408 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Blogging.Members; +using Volo.Blogging.Posts; + +namespace Volo.Blogging.Pages.Members; + +public class IndexModel : AbpPageModel +{ + private readonly IPostAppService _postAppService; + + private readonly IMemberAppService _memberAppService; + public BlogUserDto User { get; set; } + public List Posts { get; set; } + + public IndexModel(IPostAppService postAppService, IMemberAppService memberAppService) + { + _postAppService = postAppService; + _memberAppService = memberAppService; + } + + public async Task OnGetAsync(string userName) + { + User = await _memberAppService.FindAsync(userName); + + if (User is null) + { + return Redirect("/abp"); + } + + Posts = await _postAppService.GetListByUserIdAsync(User.Id); + + return Page(); + } + + public async Task OnPostAsync() + { + return Redirect($"/members/{CurrentUser.UserName}"); + } + +} \ No newline at end of file