Exemplo n.º 1
0
        public async Task <ListResponse <BacklogItemListGetResponse> > GetList(BacklogItemListGetRequest dto)
        {
            var query = DbSession.Query <BacklogItemIndexedForList, BacklogItems_ForList>();

            query = await ApplyFilters(query, dto);

            query = ApplySearch(query, dto.Search);

            var totalRecords = await query.CountAsync();

            query = ApplySorting(query, dto);

            query = query.Skip(dto.PageIndex * dto.PageSize).Take(dto.PageSize);

            var ret = await(from b in query.As <BacklogItem>()
                            select new BacklogItemListGetResponse
            {
                Id       = b.Id,
                Title    = b.Title,
                Type     = b.Type,
                Assignee = b.Assignee,
                // Have to re-calculate 'Created' and 'LastUpdated' server-side, as the entity model's fields get calculated client-side only
                Created     = b.ModifiedBy.OrderBy(m => m.Timestamp).FirstOrDefault() as ChangedByUserReference,
                LastUpdated = b.ModifiedBy.OrderBy(m => m.Timestamp).LastOrDefault() as ChangedByUserReference
            }
                            ).ToListAsync();

            ret.RemoveEntityPrefixFromIds(r => r.Assignee, r => r.Created.ActionedBy, r => r.LastUpdated.ActionedBy);

            return(new ListResponse <BacklogItemListGetResponse>(ret, totalRecords, dto.PageIndex, dto.PageSize));
        }
Exemplo n.º 2
0
 public Task <ListResponse <BacklogItemListGetResponse> > GetList([FromServices] IBacklogItemListQueryService service,
                                                                  [FromQuery] BacklogItemListGetRequest dto)
 => service.GetList(dto);
Exemplo n.º 3
0
        private async Task <IRavenQueryable <BacklogItemIndexedForList> > ApplyFilters(IRavenQueryable <BacklogItemIndexedForList> query, BacklogItemListGetRequest dto)
        {
            if (dto.Type != BacklogItemType.Unknown)
            {
                query = query.Where(t => t.Type == dto.Type);
            }

            if (dto.Tags?.Any() == true)
            {
                foreach (var tag in dto.Tags)
                {
                    query = query.Where(e => e.Tags !.Contains(tag));                                                           // Note: [Tags] is a nullable field, but when the LINQ gets converted to RQL the potential NULLs get handled
                }
            }
            if (dto.MentionsOfTheCurrentUserOnly)
            {
                var userId = GetUserIdForDynamicField();
                query = query.Where(t => t.MentionedUser ![userId] > DateTime.MinValue);                // Note: [MentionedUser] is a nullable field, but when the LINQ gets converted to RQL the potential NULLs get handled
        private async Task <IRavenQueryable <BacklogItemIndexedForList> > ApplyFilters(IRavenQueryable <BacklogItemIndexedForList> query, BacklogItemListGetRequest dto)
        {
            if (dto.Types?.Where(v => v.HasValue).Select(v => v !.Value).ToList() is var types &&
                types?.Any() == true)
            {
                query = query.Where(t => t.Type.In(types));
            }

            if (dto.States?.Where(v => v.HasValue).Select(v => v !.Value).ToList() is var states &&
                states?.Any() == true)
            {
                query = query.Where(t => t.State.In(states));
            }

            if (dto.Tags?.Any() == true)
            {
                foreach (var tag in dto.Tags.Where(t => !string.IsNullOrEmpty(t)))
                {
                    query = query.Where(e => e.Tags !.Contains(tag));                                                           // Note: [Tags] is a nullable field, but when the LINQ gets converted to RQL the potential NULLs get handled
                }
            }
            if (dto.CurrentUserRelation.HasValue)
            {
                var userId = _userResolver.GetCurrentUserId();
                query = dto.CurrentUserRelation.Value switch
                {
                    // Note: [MentionedUser] & [ModifiedByUser] are nullable fields, but when the LINQ gets converted to RQL the potential NULLs get handled
                    CurrentUserRelations.MentionsOf => query.Where(t => t.MentionedUser ![userId] > DateTime.MinValue),