/// <summary> /// Extension method to go through query params and add them to the IQueryable /// </summary> /// <typeparam name="T">Type of IQueryable</typeparam> /// <param name="q">The Queryable</param> /// <param name="query">The query model</param> /// <returns></returns> public static IQueryable <T> BuildQuery <T>(this IQueryable <T> q, DocumentQueryModel query) where T : BaseEntity { if (!string.IsNullOrWhiteSpace(query.SortBy) && query.SortBy.Equals("created", StringComparison.OrdinalIgnoreCase)) { IOrderedQueryable <T> orderBy = q.OrderByDescending(x => x.Created); if (query.SortDirection == SortDirection.Ascending) { orderBy = q.OrderBy(x => x.Created); } q = orderBy; } if (!string.IsNullOrWhiteSpace(query.Org)) { q = q.Where(x => x.Org == query.Org); } if (!string.IsNullOrWhiteSpace(query.App)) { q = q.Where(x => x.App == query.App); } return(q); }
/// <inheritdoc/> public async Task <IEnumerable <DeploymentEntity> > Get(DocumentQueryModel query) { List <DeploymentEntity> searchResult = new List <DeploymentEntity>(); try { using NpgsqlConnection conn = new NpgsqlConnection(_connectionString); await conn.OpenAsync(); NpgsqlCommand pgcom = new NpgsqlCommand(getDeploymentsSql, conn); pgcom.Parameters.AddWithValue("_org", NpgsqlDbType.Varchar, query.Org); pgcom.Parameters.AddWithValue("_app", NpgsqlDbType.Varchar, query.App); pgcom.Parameters.AddWithValue("_limit", NpgsqlDbType.Integer, query.Top ?? int.MaxValue); pgcom.Parameters.AddWithValue("_order_asc_desc", NpgsqlDbType.Varchar, query.SortDirection == SortDirection.Ascending ? "asc" : "desc"); using (NpgsqlDataReader reader = pgcom.ExecuteReader()) { while (reader.Read()) { DeploymentEntity deploymentEntity = Deserialize(reader[0].ToString()); searchResult.Add(deploymentEntity); } } return(searchResult); } catch (Exception e) { _logger.LogError(e, "DeploymentRepository // Get(DocumentQueryModel) // Exception"); throw; } }
public ServiceResponse GetAllDocuments(DocumentQueryModel queryModel) { if (queryModel == null) { queryModel = new DocumentQueryModel(); } return(documentServices.GetAllDocuments(queryModel)); }
/// <inheritdoc/> public async Task <SearchResults <DeploymentEntity> > GetAsync(DocumentQueryModel query) { query.App = _app; query.Org = _org; IEnumerable <DeploymentEntity> results = await _deploymentRepository.Get(query); return(new SearchResults <DeploymentEntity> { Results = results }); }
/// <inheritdoc/> public async Task <SearchResults <ReleaseEntity> > GetAsync(DocumentQueryModel query) { query.Org = _org; query.App = _app; IEnumerable <ReleaseEntity> results = await _releaseRepository.GetAsync <ReleaseEntity>(query); return(new SearchResults <ReleaseEntity> { Results = results }); }
public async Task <SearchResults <DeploymentEntity> > Get([FromQuery] DocumentQueryModel query) { SearchResults <DeploymentEntity> deployments = await _deploymentService.GetAsync(query); List <DeploymentEntity> laggingDeployments = deployments.Results.Where(d => d.Build.Status.Equals(BuildStatus.InProgress) && d.Build.Started.Value.AddMinutes(10) < DateTime.UtcNow).ToList(); foreach (DeploymentEntity deployment in laggingDeployments) { await _pipelineService.UpdateDeploymentStatus(deployment.Build.Id, deployment.Org); } return(deployments); }
public async Task <SearchResults <ReleaseEntity> > Get([FromQuery] DocumentQueryModel query) { SearchResults <ReleaseEntity> releases = await _releaseService.GetAsync(query); List <ReleaseEntity> laggingReleases = releases.Results.Where(d => d.Build.Status.Equals(BuildStatus.InProgress) && d.Build.Started.Value.AddMinutes(10) < DateTime.UtcNow).ToList(); foreach (ReleaseEntity release in laggingReleases) { await _pipelineService.UpdateReleaseStatus(release.Build.Id, release.Org); } return(releases); }
/// <inheritdoc/> public async Task <IEnumerable <T> > GetAsync <T>(DocumentQueryModel query) where T : BaseEntity { FeedOptions feedOptions = new FeedOptions { MaxItemCount = query.Top ?? int.MaxValue }; IDocumentQuery <T> documentQuery = _documentClient .CreateDocumentQuery <T>(_collectionUri, feedOptions) .BuildQuery(query) .AsDocumentQuery(); FeedResponse <T> response = await documentQuery.ExecuteNextAsync <T>(); return(response.AsEnumerable()); }
public async Task <SearchResults <ReleaseEntity> > Get([FromQuery] DocumentQueryModel query) => await _releaseService.GetAsync(query);
public async Task <SearchResults <DeploymentEntity> > Get([FromQuery] DocumentQueryModel query) => await _deploymentService.GetAsync(query);