Exemplo n.º 1
0
        public static async Task <IssuesPagedList> CreateAsync(
            IQueryable <GeminiIssueEntity> source,
            IssuesQueryParameters issuesQueryParameters,
            CancellationToken token)
        {
            var count = source.Count();
            var requestedIssuePagination = MetaIssuePagination.ParsePagination(issuesQueryParameters);
            int pageNumber = 0;

            List <GeminiIssueEntity> items;

            if (requestedIssuePagination != null)
            {
                pageNumber = Math.Max(1, requestedIssuePagination.PageNumber);
                items      = await GetPageAsync(source, issuesQueryParameters.PageSize, pageNumber, token).ConfigureAwait(false);
            }
            else
            {
                items = await source.Take(issuesQueryParameters.PageSize).ToListAsync(token).ConfigureAwait(false);
            }

            var meta = new MetaIssuePagination
            {
                PageNumber = pageNumber,
                PageSize   = issuesQueryParameters.PageSize,
                CheckSum   = CreateCheckSum(issuesQueryParameters)
            };

            return(new IssuesPagedList(items, count, meta));
        }
Exemplo n.º 2
0
 private static int CreateCheckSum(IssuesQueryParameters issuesQueryParameters)
 {
     return((issuesQueryParameters.Version?.GetHashCode() ?? 71) ^
            (issuesQueryParameters.AssigneeId?.GetHashCode() ?? 173) ^
            (issuesQueryParameters.ReporterId?.GetHashCode() ?? 1069) ^
            (issuesQueryParameters.Sprint?.GetHashCode() ?? 4231) ^
            (issuesQueryParameters.Year?.GetHashCode() ?? 6997));
 }
Exemplo n.º 3
0
 private string CreateResourceUri(string?page, IssuesQueryParameters issuesQueryParameters)
 {
     return(Url.Link("GetGeminiIssues", new IssuesQueryParameters
     {
         AssigneeId = issuesQueryParameters.AssigneeId,
         IncludeFields = issuesQueryParameters.IncludeFields,
         IncludeHistory = issuesQueryParameters.IncludeHistory,
         Page = page,
         PageSize = issuesQueryParameters.PageSize,
         ReporterId = issuesQueryParameters.ReporterId,
         Sprint = issuesQueryParameters.Sprint,
         Version = issuesQueryParameters.Version,
         Year = issuesQueryParameters.Year
     }));
 }
Exemplo n.º 4
0
        public static MetaIssuePagination?ParsePagination(IssuesQueryParameters issuesQueryParameters)
        {
            if (!string.IsNullOrEmpty(issuesQueryParameters.Page))
            {
                try
                {
                    var decoded = Base64Decode(issuesQueryParameters.Page);
                    var meta    = JsonSerializer.Deserialize <MetaIssuePagination>(decoded);
                    return(meta);
                }
                catch (JsonException)
                {
                    throw new ArgumentException("Invalid page parameter", nameof(issuesQueryParameters));
                }
                catch (FormatException)
                {
                    throw new ArgumentException("Invalid page parameter", nameof(issuesQueryParameters));
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        public async Task <ActionResult <IEnumerable <GeminiIssue> > > GetGeminiIssues(long projectId,
                                                                                       [FromQuery] IssuesQueryParameters issueQueryParameters)
        {
            var issues = await _geminiRepository.GetIssuesAsync(projectId, issueQueryParameters, CancellationToken.None).ConfigureAwait(false);

            var previousPageLink = issues.IssuePagination.HasPrevious() ?
                                   CreateResourceUri(issues.IssuePagination.PreviousPage, issueQueryParameters) : null;

            var nextPageLink = issues.IssuePagination.HasNext() ?
                               CreateResourceUri(issues.IssuePagination.NextPage, issueQueryParameters) : null;

            var paginationMetadata = new
            {
                totalCount = issues.IssuePagination.Count,
                pageSize   = issueQueryParameters.PageSize,
                previousPageLink,
                nextPageLink
            };

            Response.Headers.Add("X-Pagination",
                                 JsonSerializer.Serialize(paginationMetadata));

            // TODO: This destoys the pagination - but this SQL SEVER does not support it anyway
            if (!string.IsNullOrWhiteSpace(issueQueryParameters.Sprint) && int.TryParse(issueQueryParameters.Sprint, out int sprint))
            {
                var sprintIssues = issues.Where(x => x.IsInSprint(sprint, _geminiRepository.SprintCustomFieldId));
                return(Ok(_mapper.Map <IEnumerable <GeminiIssue> >(sprintIssues)));
            }

            var geminiIssues = _mapper.Map <IEnumerable <GeminiIssue> >(issues);

            foreach (var item in geminiIssues)
            {
                item.IssueUri = _geminiUrlHelper.BuilIssuedUri(item);
            }

            return(Ok(geminiIssues));
        }
Exemplo n.º 6
0
        public async Task <ActionResult <IEnumerable <GeminiIssue> > > GetGeminiAcceptedIssues(long projectId,
                                                                                               [FromQuery] IssuesQueryParameters issueQueryParameters)
        {
            var accepted = await _geminiRepository.GetAcceptedIssuesAsync(projectId, issueQueryParameters, CancellationToken.None).ConfigureAwait(false);

            var issues = accepted.ToList();

            if (!issues.Any())
            {
                return(Ok(_mapper.Map <IEnumerable <GeminiIssue> >(issues)));
            }

            var ids     = issues.Select(s => s.IssueId).ToList();
            var history = await _geminiRepository.GetIssuesHistoriesAsync(ids, CancellationToken.None).ConfigureAwait(false);

            var geminiIssues = _mapper.Map <IEnumerable <GeminiIssue> >(issues);

            foreach (var issue in geminiIssues)
            {
                if (history.ContainsKey(issue.IssueId))
                {
                    var acceptedItem = history.Single(x => x.Key == issue.IssueId).Value
                                       .FirstOrDefault(
                        c => c.History.IndexOf("angenommen", StringComparison.InvariantCultureIgnoreCase) >= 0);

                    issue.IssueUri     = _geminiUrlHelper.BuilIssuedUri(issue);
                    issue.AcceptedDate = acceptedItem?.Created;
                }
            }

            Response.Headers.Add("X-Pagination",
                                 JsonSerializer.Serialize("Not Supported"));

            return(Ok(geminiIssues));
        }
Exemplo n.º 7
0
        public Task <IEnumerable <GeminiIssueEntity> > GetAcceptedIssuesAsync(decimal projectId, IssuesQueryParameters issueQueryParameters, CancellationToken token)
        {
            var json = JsonConvert.SerializeObject(_geminiIssueEntities);
            var list = JsonConvert.DeserializeObject <IEnumerable <GeminiIssueEntity> >(json);

            if (issueQueryParameters.IncludeFields == true)
            {
                foreach (var item in list)
                {
                    item.CustomFields = _custom01;
                }
            }

            if (issueQueryParameters.IncludeHistory == true)
            {
                foreach (var item in list)
                {
                    item.HistoryItems = _history01;
                }
            }

            return(Task.FromResult(list));
        }
Exemplo n.º 8
0
 public Task <IssuesPagedList> GetIssuesAsync(decimal projectId, IssuesQueryParameters issueQueryParameters, CancellationToken token)
 {
     return(null);
 }