Skip to content

Commit

Permalink
Merge pull request #51 from skni-kod/feature/#39-filters-in-offers
Browse files Browse the repository at this point in the history
Filters in offers
  • Loading branch information
Comply5000 authored Dec 22, 2023
2 parents 1dae82d + a21a925 commit 4afbc88
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
using MediatR;
using skit.Core.Offers.Enums;
using skit.Core.Salaries.Enums;
using skit.Shared.Models;

namespace skit.Application.Offers.Queries.BrowsePublicOffers;

public sealed record BrowsePublicOffersQuery(string? Search) : PaginationRequest, IRequest<BrowsePublicOffersResponse>;
public sealed record BrowsePublicOffersQuery(
string? Search,
List<OfferSeniority>? Seniorities,
List<OfferWorkLocation>? WorkLocations,
List<string>? Cities,
decimal? SalaryFrom,
List<SalaryEmploymentType>? EmploymentType,
List<Guid>? TechnologyIds) : PaginationRequest, IRequest<BrowsePublicOffersResponse>;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MediatR;
using skit.Application.Offers.Queries.BrowsePublicOffers;
using skit.Core.Common.Extensions;
using skit.Core.Offers.Enums;
using skit.Infrastructure.DAL.EF.Context;
using skit.Shared.Extensions;
Expand All @@ -19,6 +20,8 @@ public async Task<BrowsePublicOffersResponse> Handle(BrowsePublicOffersQuery que
{
var offers = _context.Offers.AsNoTracking().Where(offer => offer.Status == OfferStatus.Public);

#region Filters

if (!string.IsNullOrWhiteSpace(query.Search))
{
var searchTxt = $"%{query.Search}%";
Expand All @@ -27,6 +30,32 @@ public async Task<BrowsePublicOffersResponse> Handle(BrowsePublicOffersQuery que
offer.Description != null && Microsoft.EntityFrameworkCore.EF.Functions.ILike(offer.Description, searchTxt));
}

if (query.Seniorities is not null && query.Seniorities.Any())
{
var querySeniorities = query.Seniorities.AggregateToFlag();
offers = offers.Where(offer => (offer.Seniority & querySeniorities) != 0);
}

if (query.WorkLocations is not null && query.WorkLocations.Any())
{
var queryWorkLocations = query.WorkLocations.AggregateToFlag();
offers = offers.Where(offer => (offer.WorkLocation & queryWorkLocations) != 0);
}

if (query.Cities is not null && query.Cities.Any(city => !string.IsNullOrWhiteSpace(city)))
offers = offers.Where(offer => offer.Addresses.Any(address => query.Cities.Contains(address.City)));

if (query.SalaryFrom is not null)
offers = offers.Where(offer => offer.Salaries.Any(salary => salary.SalaryTo >= query.SalaryFrom));

if (query.EmploymentType is not null && query.EmploymentType.Any())
offers = offers.Where(offer => offer.Salaries.Any(salary => query.EmploymentType.Contains(salary.EmploymentType)));

if (query.TechnologyIds is not null && query.TechnologyIds.Any())
offers = offers.Where(offer => offer.Technologies.Any(technology => query.TechnologyIds.Contains(technology.Id)));

#endregion

var result = await offers
.Include(offer => offer.Addresses)
.Include(offer => offer.Salaries)
Expand Down
1 change: 1 addition & 0 deletions skit.Infrastructure/DAL/Offers/Queries/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private static TechnologyDto AsDto(this Technology technology)
{
return new TechnologyDto
{
Id = technology.Id,
Name = technology.Name,
ThumUrl = technology.ThumUrl
};
Expand Down

0 comments on commit 4afbc88

Please sign in to comment.