Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Azure App config #422

Merged
merged 12 commits into from
Oct 6, 2024
4 changes: 2 additions & 2 deletions benchmarks/Jordnaer.Benchmarks/Jordnaer.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Bogus" Version="35.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.7" />
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/container_apps/Jordnaer.Chat/Jordnaer.Chat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />

<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" />
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.2.3" />
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.2.5" />

<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.3.0" />

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.7">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 0 additions & 2 deletions src/container_apps/Jordnaer.Chat/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
{
var builder = WebApplication.CreateBuilder(args);

builder.AddAzureAppConfiguration();

builder.AddSerilog();

builder.AddDatabase();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
<PackageReference Include="Serilog.Sinks.ElmahIo" Version="5.1.43" />
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.3.0" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.5.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.3.0" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions src/shared/Jordnaer.Shared/Jordnaer.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.7.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.9.1" />
<PackageReference Include="NetEscapades.EnumGenerators" Version="1.0.0-beta09" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.1.2" />
<PackageReference Include="MassTransit.Abstractions" Version="8.2.4" />
<PackageReference Include="Refit.HttpClientFactory" Version="7.2.1" />
<PackageReference Include="MassTransit.Abstractions" Version="8.2.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Jordnaer.Features.GroupSearch;

internal static class GroupSearchServiceExtensions
internal static class QueryableGroupExtensions
{
internal static IQueryable<Group> ApplyNameFilter(this IQueryable<Group> groups, string? name)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Jordnaer.Features.Search;
using Jordnaer.Shared;
using Microsoft.EntityFrameworkCore;

namespace Jordnaer.Features.UserSearch;

internal static class QueryableUserProfileExtensions
{
internal static async Task<(IQueryable<UserProfile> UserProfiles, bool AppliedOrdering)> ApplyLocationFilterAsync(
this IQueryable<UserProfile> users,
UserSearchFilter filter,
IZipCodeService zipCodeService,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(filter.Location) || filter.WithinRadiusKilometers is null)
{
return (users, false);
}

var (zipCodesWithinCircle, searchedZipCode) = await zipCodeService.GetZipCodesNearLocationAsync(
filter.Location,
filter.WithinRadiusKilometers.Value,
cancellationToken);

if (zipCodesWithinCircle.Count is 0 || searchedZipCode is null)
{
return (users, false);
}

users = users.Where(user => user.ZipCode != null &&
zipCodesWithinCircle.Contains(user.ZipCode.Value))
.OrderBy(user => Math.Abs(user.ZipCode!.Value - searchedZipCode.Value));
NielsPilgaard marked this conversation as resolved.
Show resolved Hide resolved

return (users, true);
}

internal static IQueryable<UserProfile> ApplyCategoryFilter(this IQueryable<UserProfile> users,
UserSearchFilter filter)
{
if (filter.Categories is not null && filter.Categories.Length > 0)
{
users = users.Where(user =>
user.Categories.Any(category => filter.Categories.Contains(category.Name)));
}

return users;
}

internal static IQueryable<UserProfile> ApplyNameFilter(this IQueryable<UserProfile> users, string? filter)
{
if (!string.IsNullOrWhiteSpace(filter))
{
users = users.Where(user => !string.IsNullOrEmpty(user.SearchableName) &&
EF.Functions.Like(user.SearchableName, $"%{filter}%"));
}

return users;
}

internal static IQueryable<UserProfile> ApplyChildFilters(this IQueryable<UserProfile> users,UserSearchFilter filter)
{
if (filter.ChildGender is not null)
{
users = users.Where(user =>
user.ChildProfiles.Any(child => child.Gender == filter.ChildGender));
}

if (filter is { MinimumChildAge: not null, MaximumChildAge: not null } &&
filter.MinimumChildAge == filter.MaximumChildAge)
{
users = users.Where(user =>
user.ChildProfiles.Any(child => child.Age != null &&
child.Age == filter.MinimumChildAge));
return users;
}

if (filter.MinimumChildAge is not null)
{
users = users.Where(user =>
user.ChildProfiles.Any(child => child.Age != null &&
child.Age >= filter.MinimumChildAge));
}

if (filter.MaximumChildAge is not null)
{
users = users.Where(user =>
user.ChildProfiles.Any(child => child.Age != null &&
child.Age <= filter.MaximumChildAge));
}

return users;
}
}
97 changes: 7 additions & 90 deletions src/web/Jordnaer/Features/UserSearch/UserSearchService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Jordnaer.Database;
using Jordnaer.Features.GroupSearch;
using Jordnaer.Features.Metrics;
using Jordnaer.Features.Search;
using Jordnaer.Shared;
Expand All @@ -17,16 +18,15 @@ public class UserSearchService(
IDbContextFactory<JordnaerDbContext> contextFactory)
: IUserSearchService
{

public async Task<List<UserSlim>> GetUsersByNameAsync(string currentUserId, string searchString, CancellationToken cancellationToken = default)
{
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var users = ApplyNameFilter(searchString, context.UserProfiles);
var users = context.UserProfiles.ApplyNameFilter(searchString);

var firstTenUsers = await users
.Where(user => user.Id != currentUserId)
.OrderBy(user => searchString.StartsWith(searchString))
.Take(11)
.Take(11) // We take 11 to let the frontend know we might have more than it searched for
.Select(user => new UserSlim
{
ProfilePictureUrl = user.ProfilePictureUrl,
Expand All @@ -50,10 +50,10 @@ public async Task<UserSearchResult> GetUsersAsync(UserSearchFilter filter, Cance
.Where(user => !string.IsNullOrEmpty(user.UserName))
.AsQueryable();

users = ApplyChildFilters(filter, users);
users = ApplyNameFilter(filter.Name, users);
users = ApplyCategoryFilter(filter, users);
(users, var isOrdered) = await ApplyLocationFilterAsync(filter, users, cancellationToken);
users = users.ApplyChildFilters(filter);
users = users.ApplyNameFilter(filter.Name);
users = users.ApplyCategoryFilter(filter);
(users, var isOrdered) = await users.ApplyLocationFilterAsync(filter, zipCodeService, cancellationToken);

if (!isOrdered)
{
Expand Down Expand Up @@ -94,89 +94,6 @@ public async Task<UserSearchResult> GetUsersAsync(UserSearchFilter filter, Cance
return new UserSearchResult { TotalCount = totalCount, Users = paginatedUsers };
}

private async Task<(IQueryable<UserProfile> UserProfiles, bool AppliedOrdering)> ApplyLocationFilterAsync(
UserSearchFilter filter,
IQueryable<UserProfile> users,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(filter.Location) || filter.WithinRadiusKilometers is null)
{
return (users, false);
}

var (zipCodesWithinCircle, searchedZipCode) = await zipCodeService.GetZipCodesNearLocationAsync(
filter.Location,
filter.WithinRadiusKilometers.Value,
cancellationToken);

if (zipCodesWithinCircle.Count is 0 || searchedZipCode is null)
{
return (users, false);
}

users = users.Where(user => user.ZipCode != null &&
zipCodesWithinCircle.Contains(user.ZipCode.Value))
.OrderBy(user => Math.Abs(user.ZipCode!.Value - searchedZipCode.Value));

return (users, true);
}

private static IQueryable<UserProfile> ApplyCategoryFilter(UserSearchFilter filter, IQueryable<UserProfile> users)
{
if (filter.Categories is not null && filter.Categories.Length > 0)
{
users = users.Where(user =>
user.Categories.Any(category => filter.Categories.Contains(category.Name)));
}

return users;
}

private static IQueryable<UserProfile> ApplyNameFilter(string? filter, IQueryable<UserProfile> users)
{
if (!string.IsNullOrWhiteSpace(filter))
{
users = users.Where(user => !string.IsNullOrEmpty(user.SearchableName) &&
EF.Functions.Like(user.SearchableName, $"%{filter}%"));
}

return users;
}

private static IQueryable<UserProfile> ApplyChildFilters(UserSearchFilter filter, IQueryable<UserProfile> users)
{
if (filter.ChildGender is not null)
{
users = users.Where(user =>
user.ChildProfiles.Any(child => child.Gender == filter.ChildGender));
}

if (filter is { MinimumChildAge: not null, MaximumChildAge: not null } &&
filter.MinimumChildAge == filter.MaximumChildAge)
{
users = users.Where(user =>
user.ChildProfiles.Any(child => child.Age != null &&
child.Age == filter.MinimumChildAge));
return users;
}

if (filter.MinimumChildAge is not null)
{
users = users.Where(user =>
user.ChildProfiles.Any(child => child.Age != null &&
child.Age >= filter.MinimumChildAge));
}

if (filter.MaximumChildAge is not null)
{
users = users.Where(user =>
user.ChildProfiles.Any(child => child.Age != null &&
child.Age <= filter.MaximumChildAge));
}

return users;
}

private static ReadOnlySpan<KeyValuePair<string, object?>> MakeTagList(UserSearchFilter filter)
{
return new KeyValuePair<string, object?>[]
Expand Down
36 changes: 18 additions & 18 deletions src/web/Jordnaer/Jordnaer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.22.1" />
<PackageReference Include="Blazr.RenderState.Server" Version="1.0.0" />
<PackageReference Include="Grafana.OpenTelemetry" Version="0.7.0-beta.4" />
<PackageReference Include="Grafana.OpenTelemetry" Version="1.0.1" />
<PackageReference Include="HtmlSanitizer" Version="8.1.870" />
<PackageReference Include="Markdig" Version="0.37.0" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" />
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.2.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.7">
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.SendGrid" Version="8.0.1" />
<PackageReference Include="Bogus" Version="35.6.0" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.22.0" />
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.24.0" />
<PackageReference Include="OneOf" Version="3.0.271" />
<PackageReference Include="SendGrid.Extensions.DependencyInjection" Version="1.0.1" />
<PackageReference Include="Mediator.Abstractions" Version="2.1.7" />
Expand All @@ -39,11 +39,11 @@
</PackageReference>
<PackageReference Include="Sidio.Sitemap.Blazor" Version="1.0.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="MudBlazor" Version="7.6.0" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="7.0.0" />
<PackageReference Include="FluentValidation" Version="11.9.2" />
<PackageReference Include="MudBlazor" Version="7.8.0" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="7.0.1" />
<PackageReference Include="FluentValidation" Version="11.10.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
<PackageReference Include="WYSIWYGTextEditor" Version="1.0.1" />
Expand Down
Loading