-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cef1787
commit 5806db2
Showing
12 changed files
with
123 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Hosts/BlogCore.Api/Posts/ListOutPostByBlog/ListOutPostByBlogPresenter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using BlogCore.AccessControlContext.Domain; | ||
using BlogCore.Core; | ||
using BlogCore.PostContext.UseCases.ListOutPostByBlog; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace BlogCore.Api.Posts.ListOutPostByBlog | ||
{ | ||
public class ListOutPostByBlogPresenter | ||
{ | ||
private readonly IUserRepository _userRepository; | ||
|
||
public ListOutPostByBlogPresenter(IUserRepository userRepository) | ||
{ | ||
_userRepository = userRepository; | ||
} | ||
|
||
public PaginatedItem<ListOutPostByBlogResponse> Transform(PaginatedItem<ListOutPostByBlogResponse> input) | ||
{ | ||
var authors = input.Items | ||
.Select(x => x.Author.Id) | ||
.Distinct() | ||
.Select(x => _userRepository.GetByIdAsync(x).Result) | ||
.ToList(); | ||
|
||
var posts = input.Items | ||
.Select(x => | ||
{ | ||
var author = authors.FirstOrDefault(y => y.Id == x.Author.Id.ToString()); | ||
return x.SetAuthor(new ListOutPostByBlogUserResponse(author.Id, author.FamilyName, author.GivenName)); | ||
}) | ||
.ToList(); | ||
|
||
return new PaginatedItem<ListOutPostByBlogResponse>( | ||
input.TotalItems, | ||
(int)input.TotalPages, | ||
posts); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using BlogCore.Api.Posts.ListOutPostByBlog; | ||
using BlogCore.Core; | ||
using BlogCore.Core.Helpers; | ||
using BlogCore.PostContext.Domain; | ||
using BlogCore.PostContext.UseCases.ListOutPostByBlog; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlogCore.Api.Posts | ||
{ | ||
[Route("api/public/blogs")] | ||
public class PostPublicApiController : Controller | ||
{ | ||
private readonly IMediator _eventAggregator; | ||
private readonly ListOutPostByBlogPresenter _listOutPostByBlogPresenter; | ||
|
||
public PostPublicApiController(IMediator eventAggregator, ListOutPostByBlogPresenter listOutPostByBlogPresenter) | ||
{ | ||
_eventAggregator = eventAggregator; | ||
_listOutPostByBlogPresenter = listOutPostByBlogPresenter; | ||
} | ||
|
||
[HttpGet("{blogId:guid}/posts")] | ||
public async Task<PaginatedItem<ListOutPostByBlogResponse>> GetForBlog(Guid blogId, [FromQuery] int page) | ||
{ | ||
var postResult = await _eventAggregator.Send(new ListOutPostByBlogRequest(blogId, page <= 0 ? 1 : page)); | ||
return _listOutPostByBlogPresenter.Transform(postResult); | ||
} | ||
|
||
[HttpGet("{blogId:guid}/posts/{postId:guid}")] | ||
public Post Get(Guid blogId, Guid postId) | ||
{ | ||
return Post.CreateInstance( | ||
new BlogId(IdHelper.GenerateId("34C96712-2CDF-4E79-9E2F-768CB68DD552")), | ||
"sample title", | ||
"sample excerpt", | ||
"sample body", | ||
new AuthorId(IdHelper.GenerateId("4B5F26CE-DF97-494C-B747-121D215847D8"))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters