public void CreatePagedResponse_FilterPageLargerThanTotalPages_ResetsPageNumberToMax()
        {
            var filter = new PaginationFilter(11, 1);

            var result = PagedResponse <int>
                         .CreatePagedResponse(Enumerable.Range(1, 10), filter);

            result.PageNumber.Should().Be(10);
            result.TotalPages.Should().Be(10);
        }
        public async Task <PagedResponse <ImageDto> > GetByUserAsync(string userId, PaginationFilter filter)
        {
            await CheckIfUserExists(userId);

            var allImages = (await _unitOfWork.Images
                             .QueryAsync(i =>
                                         i.OwnerId.ToString() == userId))
                            .Select(i => i.ToDto()).ToArray();

            return(PagedResponse <ImageDto> .CreatePagedResponse(allImages, filter));
        }
        public async Task <PagedResponse <PostDto> > GetByProfileAsync(string profileId, PaginationFilter filter)
        {
            await CheckIfProfileExists(profileId);

            var allPosts = (await _unitOfWork.Posts
                            .QueryAsync(p =>
                                        p.ProfileId.ToString() == profileId))
                           .Select(p => p.ToDto());

            return(PagedResponse <PostDto> .CreatePagedResponse(allPosts, filter));
        }
Beispiel #4
0
        public async Task <PagedResponse <ChatDto> > GetUserChats(PaginationFilter filter)
        {
            var principal   = _contextAccessor.HttpContext.User;
            var currentUser = await _userManager.GetUserAsync(principal);

            var allChats = (await _unitOfWork.Chats
                            .QueryAsync(c => c.Participants
                                        .Any(p => p.UserId == currentUser.Id)))
                           .Select(c => c.ToDto()).ToArray();

            return(PagedResponse <ChatDto> .CreatePagedResponse(allChats, filter));
        }
        public void CreatePagedResponse_EmptyCollection_ReturnsExpectedResponse()
        {
            var filter = new PaginationFilter(1, 1);

            var result = PagedResponse <object>
                         .CreatePagedResponse(Enumerable.Empty <object>(), filter);

            result.PageSize.Should().Be(1);
            result.TotalRecords.Should().Be(0);
            result.PageNumber.Should().Be(0);
            result.TotalPages.Should().Be(0);
            result.Data.Should().BeEmpty();
        }
Beispiel #6
0
        public async Task <PagedResponse <MessageDto> > GetGroupMessagesAsync(string chatId, PaginationFilter filter)
        {
            var chat = await _unitOfWork.Chats.GetByIdAsync(chatId);

            if (chat == null)
            {
                throw new ItemNotFoundException("Chat not found");
            }

            var allMessages = (await _unitOfWork.Messages
                               .QueryAsync(m =>
                                           m.ChatId.ToString() == chatId))
                              .Select(m => m.ToDto())
                              .OrderByDescending(m => m.TimePublished)
                              .ToArray();

            return(PagedResponse <MessageDto> .CreatePagedResponse(allMessages, filter));
        }