member profile added

pull/16313/head
Onur Pıçakcı 3 years ago
parent 289a2c73cb
commit 284d40f7ae

@ -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<BlogUserDto> FindAsync(string username);
}

@ -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<PostWithDetailsDto> CreateAsync(CreatePostDto input);
Task<PostWithDetailsDto> UpdateAsync(Guid id, UpdatePostDto input);
Task<List<PostWithDetailsDto>> GetListByUserIdAsync(Guid userId);
}
}

@ -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<BlogUser, Guid> _userRepository;
public MemberAppService(IRepository<BlogUser, Guid> userRepository)
{
_userRepository = userRepository;
}
public async Task<BlogUserDto> FindAsync(string username)
{
var user = await _userRepository.FindAsync(x => x.UserName == username);
return ObjectMapper.Map<BlogUser, BlogUserDto>(user);
}
}

@ -188,6 +188,17 @@ namespace Volo.Blogging.Posts
return ObjectMapper.Map<Post, PostWithDetailsDto>(post);
}
public async Task<List<PostWithDetailsDto>> GetListByUserIdAsync(Guid userId)
{
var posts = await PostRepository.GetListByUserIdAsync(userId);
if (CurrentUser != null)
{
}
return ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts);
}
[Authorize(BloggingPermissions.Posts.Create)]
public async Task<PostWithDetailsDto> CreateAsync(CreatePostDto input)
{

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

@ -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<List<Post>> 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<IQueryable<Post>> WithDetailsAsync()
{
return (await GetQueryableAsync()).IncludeDetails();

@ -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<List<PostWithDetailsDto>> GetListByUserIdAsync(Guid userId)
{
return _postAppService.GetListByUserIdAsync(userId);
}
[HttpDelete]
[Route("{id}")]

@ -58,5 +58,13 @@ namespace Volo.Blogging.Posts
return await query.OrderByDescending(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<Post>> 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));
}
}
}

@ -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<DynamicJavaScriptProxyOptions>(options =>

@ -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<BloggingResource> L
@inject ICurrentUser CurrentUser
<main class="pt-4" id="MemberDetail">
<div class="container">
<div class="row gx-lg-5">
<div class="col-md-4 mb-5 mb-md-0">
<div class="card h-auto member-profile-info">
<div class="card-body">
@if (Model.User.UserName == CurrentUser.UserName)
{
<div class="d-inline-block position-relative">
<img src="~/assets/noimg-user.jpeg" loading="lazy" data-src="https://localhost:44300/api/account/profile-picture-file/ + @Model.User.Id" class="profile-pic"/>
</div>
}
else
{
<img src="~/assets/noimg-user.jpeg" loading="lazy" data-src="https://localhost:44300/api/account/profile-picture-file/ + @Model.User.Id" class="profile-pic"/>
}
@if (Model.User.UserName != null)
{
<h2 class="m-0">@Model.User.UserName</h2>
}
<small class="d-block">@L["UserName"].Value.ToUpper()</small>
<h5>@Model.User.UserName</h5>
</div>
</div>
</div>
<div class="col-md-8">
<abp-tabs>
<abp-tab name="all-posts" title="All @L["Blogs"].Value">
<div class="mt-4 pt-3">
@foreach (var post in Model.Posts)
{
<div class="post-item">
<div class="post-type-cont">
<a href="/members/@Model.User.UserName" class="text-decoration-none">
<img src="~/assets/noimg-user.jpeg" data-src="https://localhost:44300/api/account/profile-picture-file/@Model.User.Id" class="post-member-img rounded-circle d-block">
</a>
</div>
<div class="post-detail-cont">
<div class="post-info fs-12 mb-2">
<a href="/members/@Model.User.UserName" class="text-decoration-none">
<span class="text-dark dot">@Model.User.UserName</span>
</a>
<span class="text-dark-200 dot">@post.CreationTime.ToString("MMMM yyyy")</span>
<span class="text-dark-200">@post.ReadCount.ToString() @L["Views"]</span>
</div>
<h3 class="post-title mb-3">
@if ((post.Title).Any())
{
@foreach (var highlight in post.Title)
{
@Html.Raw(highlight)
}
}
else
{
@post.Title
}
</h3>
</div>
<div class="post-img-cont">
<img src="~/assets/noimg.png" data-src="@post.CoverImage" class="" loading="lazy"/>
</div>
</div>
}
</div>
</abp-tab>
</abp-tabs>
</div>
</div>
</div>
</main>

@ -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<PostWithDetailsDto> Posts { get; set; }
public IndexModel(IPostAppService postAppService, IMemberAppService memberAppService)
{
_postAppService = postAppService;
_memberAppService = memberAppService;
}
public async Task<IActionResult> 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<IActionResult> OnPostAsync()
{
return Redirect($"/members/{CurrentUser.UserName}");
}
}
Loading…
Cancel
Save