public async Task <List <AgregatorValue> > GetTopThreeJobs() { OpportunitySearch resultQuery = await GetOpportunities(0, true, 0); List <AgregatorValue> topSkillsOpportunity = resultQuery.Aggregators.Skill.Take(3).ToList(); return(topSkillsOpportunity); }
private static Func <Opportunity, bool> GetEligibleOpportunityPredicate(OpportunitySearch opportunitySearch) { return(o => (opportunitySearch.CauseIds == null || o.Organization.Cause != null && opportunitySearch.CauseIds.Contains(o.Organization.Cause.Id)) && (opportunitySearch.CategoryIds == null || opportunitySearch.CategoryIds.Contains(o.Category.Id)) && (opportunitySearch.OrganizationIds == null || opportunitySearch.OrganizationIds.Contains(o.Organization.Id)) && (opportunitySearch.CommunityIds == null || o.Community != null && opportunitySearch.CommunityIds.Contains(o.Community.Id)) && (opportunitySearch.OpportunityType == OpportunityType.All || opportunitySearch.OpportunityType == o.OpportunityType) && o.Approved); }
public async Task <List <OpportunityResult> > SearchOpportunities(int pageNumber, int size, int offset, string name, bool?placeBased, string?status, string?type, string?currency, string?periodicity, double?amount, string?skill) { if (!string.IsNullOrEmpty(name) || placeBased.HasValue || !string.IsNullOrEmpty(status) || !string.IsNullOrEmpty(currency) || !string.IsNullOrEmpty(periodicity) || amount.HasValue || !string.IsNullOrEmpty(skill)) { return(await SearchWithFilters(pageNumber, size, name, offset, placeBased, status, type, currency, periodicity, amount, skill)); } else { OpportunitySearch resultQuery = await GetOpportunities(size, false, size *(pageNumber - 1)); return(resultQuery.Results); } }
private async Task <OpportunitySearch> GetOpportunities(int size, bool aggregator, int offset) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("?size="); stringBuilder.Append(size.ToString()); stringBuilder.Append("&aggregate="); stringBuilder.Append(aggregator.ToString().ToLower()); stringBuilder.Append("&offset="); stringBuilder.Append(offset.ToString()); var requestUrl = _apiClient.CreateRequestUri(stringBuilder.ToString()); OpportunitySearch result = new OpportunitySearch(); result = await _apiClient.PostAsync <OpportunitySearch>(requestUrl, result); return(result); }
public async Task <IActionResult> Search([FromBody] OpportunitySearch opportunitySearch) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <Opportunity> opportunities = await MemoryCacheImpl.GetOpportunitiesAcceptingApplications(_memoryCache, _context); List <OpportunityViewModel> opportunityViews = opportunities .Where(GetEligibleOpportunityPredicate(opportunitySearch)) .Select(OpportunityViewModel.FromOpportunity) .OrderByDescending(x => x.Id) .ToList(); return(Ok(opportunityViews)); }
public async Task <IActionResult> Search([FromBody] OpportunitySearch opportunitySearch) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <Opportunity> opportunities = await VollyMemoryCache.GetAllOpportunities(_memoryCache, _context); List <OpportunityView> opportunityViews = opportunities .Where(GetEligibleOpportunityPredicate(opportunitySearch)) .Select(OpportunityView.FromOpportunity) .Where(o => o.OccurrenceViews.Count > 0) .ToList(); return(Ok(Sort(opportunityViews, opportunitySearch.Sort))); }
private async Task <List <OpportunityResult> > SearchWithFilters(int pageNumber, int size, string name, int offset, bool?placeBased, string?status, string?type, string?currency, string?periodicity, double?amount, string?skill) { List <OpportunityResult> result = new List <OpportunityResult>(); if (offset > 0) { _offset = offset; } else { _offset = 1; } while (result.Count < size) { OpportunitySearch resultQuery = await GetOpportunities(size, false, size *(_offset - 1)); foreach (OpportunityResult item in resultQuery.Results) { bool matchFound = false; if (!string.IsNullOrEmpty(name)) { matchFound = CheckFilter(matchFound, item.Objective.ToLower().Contains(name.ToLower())); if (!matchFound) { continue; } } if (placeBased.HasValue) { matchFound = CheckFilter(matchFound, item.Remote == placeBased); if (!matchFound) { continue; } } if (!string.IsNullOrEmpty(status)) { matchFound = CheckFilter(matchFound, item.Status == status); if (!matchFound) { continue; } } if (!string.IsNullOrEmpty(type)) { matchFound = CheckFilter(matchFound, item.Type == type); if (!matchFound) { continue; } } if (!string.IsNullOrEmpty(currency)) { if (item.Compensation != null && item.Compensation.Data != null) { matchFound = CheckFilter(matchFound, item.Compensation.Data.Currency == currency); if (!matchFound) { continue; } } else { continue; } } if (!string.IsNullOrEmpty(periodicity)) { if (item.Compensation != null && item.Compensation.Data != null) { matchFound = CheckFilter(matchFound, item.Compensation.Data.Periodicity == periodicity); if (!matchFound) { continue; } } else { continue; } } if (amount.HasValue) { if (item.Compensation != null && item.Compensation.Data != null) { matchFound = CheckFilter(matchFound, (item.Compensation.Data.MinAmount <= amount && item.Compensation.Data.MinAmount >= amount)); if (!matchFound) { continue; } } else { continue; } } if (!string.IsNullOrEmpty(skill)) { matchFound = CheckFilter(matchFound, item.Skills.Select(x => x.Name.ToLower() == skill.ToLower()).Count() > 0); if (!matchFound) { continue; } } if (matchFound) { result.Add(item); } } _offset++; } return(result); }
private static Func <Opportunity, bool> GetEligibleOpportunityPredicate(OpportunitySearch opportunitySearch) { return(o => opportunitySearch.OpportunityType == -1 || (int)o.OpportunityType == opportunitySearch.OpportunityType); }