Created
October 16, 2017 08:50
-
-
Save thangchung/a0185b50302905ff6391a000a3511fa5 to your computer and use it in GitHub Desktop.
Applying clean architecture on web application with modular patterns
This file contains hidden or 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
using BlogCore.AccessControlContext.Core.Domain; | |
using BlogCore.Core; | |
using BlogCore.PostContext.UseCases.ListOutPostByBlog; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reactive.Linq; | |
using System.Threading.Tasks; | |
namespace BlogCore.Api.Features.Posts.ListOutPostByBlog | |
{ | |
public class ListOutPostByBlogPresenter | |
{ | |
private readonly IUserRepository _userRepository; | |
public ListOutPostByBlogPresenter(IUserRepository userRepository) | |
{ | |
_userRepository = userRepository; | |
} | |
public async Task<PaginatedItem<ListOutPostByBlogResponse>> Transform(IObservable<PaginatedItem<ListOutPostByBlogResponse>> stream) | |
{ | |
var result = await stream.Select(x => x); | |
var authors = result.Items | |
.Select(x => x.Author.Id) | |
.Distinct() | |
.Select(y => _userRepository.GetByIdAsync(y).Result) | |
.ToList(); | |
var items = result.Items.Select(x => | |
{ | |
var author = authors.FirstOrDefault(au => au.Id == x.Author.Id.ToString()); | |
return x.SetAuthor(author?.Id, author?.FamilyName, author?.GivenName); | |
}); | |
return new PaginatedItem<ListOutPostByBlogResponse>( | |
result.TotalItems, | |
(int)result.TotalPages, | |
items.ToList()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment