Exemplo n.º 1
0
            public async Task <PaginatedList <ConversationMessageDto> > Handle(MessagesQuery query,
                                                                               CancellationToken cancellationToken)
            {
                var key = query.Identify();

                try
                {
                    _logger.LogInformation("[WLODZIMIERZ.API / Conversations] Reading from the cache: {Name} {@Query}",
                                           nameof(MessagesQuery), query);

                    return(await ReadFromCache(key));
                }
                catch (NotFoundException)
                {
                    _logger.LogWarning(
                        "[WLODZIMIERZ.API / Conversations] No entry found for the passed key in the cache");

                    _logger.LogInformation(
                        "[WLODZIMIERZ.API / Conversations] Reading from the database: {Name} {@Query}",
                        nameof(MessagesQuery), query);

                    return(await ReadFromDatabase(query, key));
                }
            }
Exemplo n.º 2
0
 private async Task <PaginatedList <ConversationMessageDto> > ReadFromDatabase(MessagesQuery query, object key)
 {
     return(await _context.ConversationMessages
            .Where(e => e.Conversation.ConversationId == query.ConversationId)
            .OrderByDescending(x => x.Publish)
            .ProjectTo <ConversationMessageDto>(_mapper.ConfigurationProvider)
            .ProjectToPaginatedListAsync(query.PageNumber, query.PageSize)
            .MapUsersAsync(_usersFacade)
            .Cache(_cache, key));
 }
Exemplo n.º 3
0
            private async Task <PaginatedList <ConversationMessageDto> > ReadFromDatabase(MessagesQuery query)
            {
                var messages = await _context.ConversationMessages
                               .Where(e => e.Conversation.ConversationId == query.ConversationId)
                               .OrderByDescending(x => x.Publish)
                               .ProjectTo <ConversationMessageDto>(_mapper.ConfigurationProvider)
                               .PaginatedListAsync(query.PageNumber, query.PageSize);

                await _usersFacade.MapAsync(messages);

                return(messages);
            }
Exemplo n.º 4
0
 public async Task <PaginatedList <ConversationMessageDto> > Handle(MessagesQuery request,
                                                                    CancellationToken cancellationToken)
 {
     return(await ReadFromDatabase(request));
 }