Exemplo n.º 1
0
            // Helpers.

            private async Task <PaginatedList <ConversationDto> > ReadFromDatabase(ConversationsQuery query, object key)
            {
                return(await _context.Conversations
                       .Where(e => e.LeftUserId == query.OwnerUserId || e.RightUserId == query.OwnerUserId)
                       .OrderBy(x => x.ConversationId)
                       .ProjectTo <ConversationDto>(_mapper.ConfigurationProvider)
                       .ProjectToPaginatedListAsync(query.PageNumber, query.PageSize)
                       .MapLastMessagesAsync(_context, _mapper)
                       .MapUsersAsync(_usersFacade));

                // .Cache(_cache, key);
            }
Exemplo n.º 2
0
            public async Task <PaginatedList <ConversationDto> > Handle(ConversationsQuery query,
                                                                        CancellationToken cancellationToken)
            {
                var key = query.Identify();

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

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

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

                    return(await ReadFromDatabase(query, key));
                }
            }