Browse Source

Post index & detail page

pull/318/head
Yunus Emre Kalkan 8 years ago
parent
commit
47cece1b6b
  1. 5623
      modules/blogging/app/Volo.BloggingTestApp/Logs/logs.txt
  2. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs
  3. 11
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/GetPostInput.cs
  4. 16
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs
  5. 14
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs
  6. 2
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs
  7. 14
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs
  8. 34
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  9. 14
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs
  10. 32
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs
  11. 12
      modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs
  12. 4
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Index.cshtml
  13. 4
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
  14. 24
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs
  15. 11
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml
  16. 23
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs

5623
modules/blogging/app/Volo.BloggingTestApp/Logs/logs.txt

File diff suppressed because one or more lines are too long

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Blogs/IBlogAppService.cs

@ -10,5 +10,7 @@ namespace Volo.Blogging.Blogs
public interface IBlogAppService : IApplicationService
{
Task<ListResultDto<BlogDto>> GetListAsync();
Task<BlogDto> GetByShortNameAsync(string shortName);
}
}

11
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/GetPostInput.cs

@ -0,0 +1,11 @@
using System;
namespace Volo.Blogging.Posts
{
public class GetPostInput
{
public string Title { get; set; }
public Guid BlogId { get; set; }
}
}

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

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Volo.Blogging.Posts
{
public interface IPostAppService : IApplicationService
{
ListResultDto<PostDto> GetPostsByBlogId(Guid id);
Task<PostDto> GetPost(GetPostInput input);
}
}

14
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs

@ -0,0 +1,14 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Volo.Blogging.Posts
{
public class PostDto : EntityDto<Guid>
{
public Guid BlogId { get; protected set; }
public string Title { get; protected set; }
public string Content { get; set; }
}
}

2
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs

@ -1,5 +1,6 @@
using AutoMapper;
using Volo.Blogging.Blogs;
using Volo.Blogging.Posts;
namespace Volo.Blogging
{
@ -8,6 +9,7 @@ namespace Volo.Blogging
public BloggingApplicationAutoMapperProfile()
{
CreateMap<Blog, BlogDto>();
CreateMap<Post, PostDto>();
}
}
}

14
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.UI;
namespace Volo.Blogging.Blogs
{
@ -21,5 +22,18 @@ namespace Volo.Blogging.Blogs
ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs)
);
}
public async Task<BlogDto> GetByShortNameAsync(string shortName)
{
var blog = await _blogRepository.FindByShortNameAsync(shortName);
if (blog == null)
{
throw new UserFriendlyException("Blog Doesn't exist");
}
return ObjectMapper.Map<Blog, BlogDto>(blog);
}
}
}

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

@ -0,0 +1,34 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using System.Collections.Generic;
namespace Volo.Blogging.Posts
{
public class PostAppService : ApplicationService, IPostAppService
{
private readonly IPostRepository _postRepository;
public PostAppService(IPostRepository postRepository)
{
_postRepository = postRepository;
}
public ListResultDto<PostDto> GetPostsByBlogId(Guid id)
{
var posts = _postRepository.GetPostsByBlogId(id);
return new ListResultDto<PostDto>(
ObjectMapper.Map<List<Post>, List<PostDto>>(posts));
}
public async Task<PostDto> GetPost(GetPostInput input)
{
var post = await _postRepository.GetPost(input.BlogId, input.Title);
return ObjectMapper.Map<Post,PostDto>(post);
}
}
}

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

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Volo.Blogging.Posts
{
public interface IPostRepository : IBasicRepository<Post, Guid>
{
List<Post> GetPostsByBlogId(Guid id);
Task<Post> GetPost(Guid blogId, string title);
}
}

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

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Blogging.Blogs;
using Volo.Blogging.EntityFrameworkCore;
namespace Volo.Blogging.Posts
{
public class EfCorePostRepository : EfCoreRepository<IBloggingDbContext, Post, Guid>, IPostRepository
{
public EfCorePostRepository(IDbContextProvider<IBloggingDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public List<Post> GetPostsByBlogId(Guid id)
{
return DbSet.Where(p => p.BlogId == id).ToList();
}
public async Task<Post> GetPost(Guid blogId, string title)
{
return await DbSet.FirstOrDefaultAsync(p => p.BlogId == blogId && p.Title == title);
}
}
}

12
modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.Modularity;
@ -27,7 +28,14 @@ namespace Volo.Blogging
{
options.FileSets.AddEmbedded<BloggingWebModule>("Volo.Blogging");
});
services.Configure<RazorPagesOptions>(options =>
{
//TODO: Make configurable!
options.Conventions.AddPageRoute("/Blog/Posts/Index", "blog/{blogShortName}");
options.Conventions.AddPageRoute("/Blog/Posts/Detail", "blog/{blogShortName}/{postTitle}");
});
services.AddAssemblyOf<BloggingWebModule>();
}

4
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Index.cshtml

@ -11,8 +11,6 @@
<ul>
@foreach (var blog in Model.Blogs)
{
<li>
@blog.Name
</li>
<li><a asp-page="./Posts/Index" asp-route-blogShortName="@blog.ShortName">@blog.Name</a></li>
}
</ul>

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

@ -3,3 +3,7 @@
@model DetailModel
@{
}
<h2>@Model.Post.Title</h2>
<p>@Model.Post.Content</p>

24
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs

@ -4,13 +4,35 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Blogging.Blogs;
using Volo.Blogging.Posts;
namespace Volo.Blogging.Pages.Blog.Posts
{
public class DetailModel : PageModel
{
public void OnGet()
private readonly IPostAppService _postAppService;
private readonly IBlogAppService _blogAppService;
[BindProperty(SupportsGet = true)]
public string BlogShortName { get; set; }
[BindProperty(SupportsGet = true)]
public string PostTitle { get; set; }
public PostDto Post { get; set; }
public DetailModel(IPostAppService postAppService, IBlogAppService blogAppService)
{
_postAppService = postAppService;
_blogAppService = blogAppService;
}
public async void OnGet()
{
var blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetPost(new GetPostInput(){BlogId = blog.Id , Title = PostTitle});
}
}
}

11
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml

@ -1,4 +1,15 @@
@page
@model Volo.Blogging.Pages.Blog.Posts.IndexModel
@{
}
<h2>
Posts
</h2>
<ul>
@foreach (var post in Model.Posts)
{
<li><a asp-page="./Detail" asp-route-postTitle="@post.Title" asp-route-blogShortName="@Model.BlogShortName">@post.Title</a></li>
}
</ul>

23
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs

@ -4,13 +4,34 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Abp.Application.Dtos;
using Volo.Blogging.Blogs;
using Volo.Blogging.Posts;
namespace Volo.Blogging.Pages.Blog.Posts
{
public class IndexModel : PageModel
{
public void OnGet()
private readonly IPostAppService _postAppService;
private readonly IBlogAppService _blogAppService;
[BindProperty(SupportsGet = true)]
public string BlogShortName { get; set; }
public IReadOnlyList<PostDto> Posts { get; set; }
public IndexModel(IPostAppService postAppService, IBlogAppService blogAppService)
{
_postAppService = postAppService;
_blogAppService = blogAppService;
}
public async Task OnGet()
{
var blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Posts = _postAppService.GetPostsByBlogId(blog.Id).Items;
}
}
}
Loading…
Cancel
Save