예제 #1
0
        public async Task <ServiceResponse <User> > GetUserAsync(string username)
        {
            var entities = await _tableContext.GetEntities <TrackerEntryEntity>(username);

            var serviceResponse = new ServiceResponse <User>
            {
                ServiceResponseStatus = ServiceResponseStatus.NotFound
            };

            if (entities.Any())
            {
                var user = new User(username, new List <Repository>());
                foreach (var entity in entities)
                {
                    bool addToList = false;

                    var        info = GetInfo(entity.RowKey);
                    Repository repo = user.RepositoryPrAddedTo
                                      .FirstOrDefault(repo => repo.Owner.Equals(info.Owner, StringComparison.OrdinalIgnoreCase) &&
                                                      repo.Name.Equals(info.RepoName, StringComparison.OrdinalIgnoreCase));
                    if (repo == null)
                    {
                        repo      = new Repository(info.Owner, info.RepoName, entity.Url, new List <PullRequest>());
                        addToList = true;
                    }
                    var prs = entities.Where(e => e.RowKey.StartsWith($"{info.Owner}:{info.RepoName}", StringComparison.OrdinalIgnoreCase));
                    foreach (var pr in prs)
                    {
                        var id = int.Parse(pr.RowKey.Substring(pr.RowKey.LastIndexOf(':') + 1));
                        if (!repo.Prs.Any(pr => pr.PrId == id))
                        {
                            if (entity.Status is null)
                            {
                                var response = await ValidatePrStatus(repo.Owner, repo.Name, id);

                                repo.Prs.Add(new PullRequest(id, entity.Url, response));
                            }
                            else
                            {
                                repo.Prs.Add(new PullRequest(id, entity.Url, entity.Status));
                            }
                        }
                    }
                    if (addToList)
                    {
                        user.RepositoryPrAddedTo.Add(repo);
                    }
                }

                serviceResponse = new ServiceResponse <User>
                {
                    Content = user,
                    ServiceResponseStatus = ServiceResponseStatus.Ok
                };
            }

            return(serviceResponse);
        }
예제 #2
0
        public async Task <ServiceResponse <IEnumerable <Project> > > GetAllProjectsAsync()
        {
            var projectEntities = await _tableContext.GetEntities <ProjectEntity>("Project");

            //todo: add in error handling
            var response = new ServiceResponse <IEnumerable <Project> >
            {
                Content = projectEntities.Select(x => new Project(x)),
                ServiceResponseStatus = ServiceResponseStatus.Ok,
                Message = "Successful Retrieval"
            };

            return(response);
        }
        public async Task <ServiceResponse <User> > GetUserAsync(string username)
        {
            var entities = await _tableContext.GetEntities <TrackerEntryEntity>(username);

            var serviceResponse = new ServiceResponse <User>
            {
                ServiceResponseStatus = ServiceResponseStatus.NotFound
            };

            if (entities.Any())
            {
                var user = new User(username, new List <Repository>());
                foreach (var entity in entities)
                {
                    bool add  = false;
                    var  info = entity.RowKey.Split(':', StringSplitOptions.RemoveEmptyEntries);
                    if (info.Length != 3)
                    {
                        // TODO: define how to proceed with this.. this is corrupted data!
                        continue;
                    }
                    var owner    = info[0];
                    var repoName = info[1];
                    var prId     = int.Parse(info[2]);

                    Repository repo;
                    var        temp = user.RepositoryPrAddedTo
                                      .FirstOrDefault(repo => repo.Owner.Equals(owner, StringComparison.OrdinalIgnoreCase) &&
                                                      repo.Name.Equals(repoName, StringComparison.OrdinalIgnoreCase));
                    if (temp != null)
                    {
                        repo = temp;
                    }
                    else
                    {
                        repo = new Repository(owner, repoName, entity.Url, new List <PullRequest>());
                        add  = true;
                    }
                    var prs = entities.Where(e => e.RowKey.StartsWith($"{owner}:{repoName}", StringComparison.OrdinalIgnoreCase));
                    foreach (var pr in prs)
                    {
                        var id = int.Parse(pr.RowKey.Substring(pr.RowKey.LastIndexOf(':') + 1));
                        if (!repo.Prs.Any(pr => pr.PrId == id))
                        {
                            repo.Prs.Add(new PullRequest(id, entity.Url));
                        }
                    }
                    if (add)
                    {
                        user.RepositoryPrAddedTo.Add(repo);
                    }
                }

                serviceResponse = new ServiceResponse <User>
                {
                    Content = user,
                    ServiceResponseStatus = ServiceResponseStatus.Ok
                };
            }

            return(serviceResponse);
        }