Skip to content

Commit

Permalink
Merge branch 'main' into feature/posts
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Jan 6, 2025
2 parents 1c724b6 + a02095b commit 0ac19b4
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public static WebApplicationBuilder AddDatabase(this WebApplicationBuilder build
{
var connectionString = GetConnectionString(builder.Configuration);

builder.Services
.AddSqlServer<JordnaerDbContext>(connectionString,
optionsBuilder => optionsBuilder.UseAzureSqlDefaults());
builder.Services.AddAzureSql<JordnaerDbContext>(connectionString);

builder.Services.AddHealthChecks().AddSqlServer(connectionString);

Expand Down
4 changes: 2 additions & 2 deletions src/container_apps/Jordnaer.Chat/Jordnaer.Chat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<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.3.3" />
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.3.4" />

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

Expand All @@ -21,7 +21,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static WebApplicationBuilder AddSerilog(this WebApplicationBuilder builde
{
if (!builder.Environment.IsDevelopment())
{

builder.Services
.AddOptions<GrafanaLokiOptions>()
.BindConfiguration(GrafanaLokiOptions.SectionName)
Expand Down
22 changes: 22 additions & 0 deletions src/shared/Jordnaer.Shared/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Jordnaer.Shared.Extensions;
public static class EnumExtensions
{
public static DisplayAttribute? GetDisplayAttribute(this Enum enumValue)
{
return enumValue.GetType()
.GetField(enumValue.ToString())?.GetCustomAttribute<DisplayAttribute>();
}

public static string GetDisplayName(this Enum enumValue)
{
return enumValue.GetDisplayAttribute()?.Name ?? enumValue.ToString();
}
}
4 changes: 0 additions & 4 deletions src/web/Jordnaer/Components/Routes.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
@using Blazr.RenderState
@inject Blazr.RenderState.IBlazrRenderStateService RenderStateService


@* @if (RenderStateService.IsPreRender && RenderStateService.RenderState is not BlazrRenderState.None)
{ TODO: Figure out how to make a good loader
<LoadingScreen />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,8 @@ public static WebApplicationBuilder AddDatabase(this WebApplicationBuilder build
{
var connectionString = GetConnectionString(builder.Configuration);

builder.Services
.AddDbContextFactory<JordnaerDbContext>(
optionsBuilder =>
optionsBuilder.UseSqlServer(connectionString,
contextOptionsBuilder =>
contextOptionsBuilder.UseAzureSqlDefaults()),
builder.Services.AddDbContextFactory<JordnaerDbContext>(
optionsBuilder => optionsBuilder.UseAzureSql(connectionString),
ServiceLifetime.Scoped);

builder.Services.AddHealthChecks().AddSqlServer(connectionString);
Expand Down
21 changes: 10 additions & 11 deletions src/web/Jordnaer/Features/Chat/ChatMessageList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
public bool LastMessageWasSentSuccessfullyByCurrentUser { get; set; }

private MudTextField<string> _messageInput = new();
private bool _isActiveChatPublished => ActiveChat?.Messages.Count is not 0;

private bool IsMessageFromSelf(ChatMessageDto message) => message.SenderId == CurrentUser.Id;

Expand Down Expand Up @@ -210,26 +209,26 @@
}

var message = new ChatMessageDto
{
ChatId = ActiveChat.Id,
Id = NewId.NextGuid(),
SentUtc = DateTime.UtcNow,
SenderId = CurrentUser.Id!,
Text = _messageInput.Value
};
{
ChatId = ActiveChat.Id,
Id = NewId.NextGuid(),
SentUtc = DateTime.UtcNow,
SenderId = CurrentUser.Id!,
Text = _messageInput.Value
};

await _messageInput.BlurAsync();
await _messageInput.Clear();

ActiveChat.Messages.Add(message);

if (_isActiveChatPublished)
if (ActiveChat.Messages.Count is 1) // If we have 1 message, we just started the chat
{
await ChatService.SendMessageAsync(message);
await ChatService.StartChatAsync(ActiveChat.ToStartChatCommand(CurrentUser.Id!));
}
else
{
await ChatService.StartChatAsync(ActiveChat.ToStartChatCommand(CurrentUser.Id!));
await ChatService.SendMessageAsync(message);
}

await _messageInput.FocusAsync();
Expand Down
28 changes: 16 additions & 12 deletions src/web/Jordnaer/Features/Chat/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,25 @@ public async Task<int> GetUnreadMessageCountAsync(string userId, CancellationTok
return unreadMessageCount;
}

private const string NotFound = "Chat does not exist, unable to get messages for it.";

public async Task<OneOf<List<ChatMessageDto>, Error<string>>> GetChatMessagesAsync(string userId, Guid chatId, int skip, int take, CancellationToken cancellationToken = default)
{
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
if (!await IsCurrentUserPartOfChat(userId, chatId, context, cancellationToken))

var chat = await context.Chats
.AsNoTracking()
.AsSingleQuery()
.Include(chat => chat.Recipients)
.FirstOrDefaultAsync(x => x.Id == chatId, cancellationToken);
if (chat is null)
{
logger.LogDebug(NotFound);
return new Error<string>(NotFound);
}

// Check if any of the recipients are the user we're fetching messages for
if (chat.Recipients.All(x => x.Id != userId))
{
logger.LogWarning(
"Tried to get chat messages for chat {ChatId} and UserId {UserId}, but that user is not part of that chat. Access denied.", chatId, userId);
Expand Down Expand Up @@ -182,15 +197,4 @@ public async Task<OneOf<Guid, NotFound>> GetChatByUserIdsAsync(string currentUse
? new NotFound()
: existingChat.Id;
}

private static async Task<bool> IsCurrentUserPartOfChat(string userId, Guid chatId, JordnaerDbContext context, CancellationToken cancellationToken = default)
{
var chat = await context
.Chats
.AsNoTracking()
.FirstOrDefaultAsync(chat => chat.Id == chatId &&
chat.Recipients.Any(recipient => recipient.Id == userId), cancellationToken);

return chat != null;
}
}
4 changes: 2 additions & 2 deletions src/web/Jordnaer/Features/Profile/EditChildProfileTabs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@

private void RemoveChild(MudTabPanel obj)
{
var tab = Parent.ChildProfiles.Find(e => e.Id == (Guid) obj.ID);
var tab = Parent.ChildProfiles.Find(e => e.Id == (Guid?) obj.ID);
if (tab is null)
{
return;
}
Parent.ChildProfiles.Remove(tab);

var editChildProfileComponent = _editChildProfileComponents.Find(e => e.ChildProfile.Id == (Guid) obj.ID);
var editChildProfileComponent = _editChildProfileComponents.Find(e => e.ChildProfile.Id == (Guid?) obj.ID);
if (editChildProfileComponent is null)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@if (user.Children.Count is not 0)
{
<MudText Class="my-4" Typo="Typo.h6">Børn</MudText>
<MudChipSet ReadOnly Class="d-flex flex-wrap justify-start flex-grow-1 gap-3" T="MudBadge">
<MudChipSet ReadOnly Class="d-flex flex-wrap justify-center flex-grow-1 gap-3" T="MudBadge">
@foreach (var child in user.Children.OrderBy(c => c.DateOfBirth))
{
<MudBadge Color="Color.Success" Overlap Origin="Origin.TopCenter" Content="GetAgeString(child)">
Expand Down
5 changes: 2 additions & 3 deletions src/web/Jordnaer/Jordnaer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.23.0" />
<PackageReference Include="Blazr.RenderState.Server" Version="1.0.0" />
<PackageReference Include="Grafana.OpenTelemetry" Version="1.1.0" />
<PackageReference Include="HtmlSanitizer" Version="8.1.870" />
<PackageReference Include="Markdig" Version="0.38.0" />
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" />
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.3.3" />
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.3.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="9.0.0" />
Expand All @@ -26,7 +25,7 @@
<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.SqlServer" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.SendGrid" Version="8.0.1" />
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.24.0" />
Expand Down
3 changes: 3 additions & 0 deletions src/web/Jordnaer/Pages/Chat/ChatPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@inject NavigationManager Navigation
@inject IJSRuntime JsRuntime

@using System.Diagnostics
@implements IAsyncDisposable

@attribute [Authorize]
Expand Down Expand Up @@ -203,6 +204,8 @@

private async Task SelectChat(ChatDto chat)
{
Debug.Assert(chat is not null);

_activeChat = chat;

await LoadMessages();
Expand Down
3 changes: 1 addition & 2 deletions src/web/Jordnaer/Pages/Profile/MyProfile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@inject IProfileCache ProfileCache
@inject IProfileService ProfileService
@inject ISnackbar Snackbar
@inject IBlazrRenderStateService RenderStateService

@attribute [Authorize]

Expand Down Expand Up @@ -135,7 +134,7 @@

protected override async Task OnInitializedAsync()
{
if (RenderStateService.IsPreRender)
if (!RendererInfo.IsInteractive)
{
return;
}
Expand Down
3 changes: 0 additions & 3 deletions src/web/Jordnaer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Azure.Storage.Blobs;
using Blazored.LocalStorage;
using Blazored.SessionStorage;
using Blazr.RenderState.Server;
using Jordnaer.Components.Account;
using Jordnaer.Extensions;
using Jordnaer.Features.Category;
Expand Down Expand Up @@ -76,8 +75,6 @@
builder.AddGroupServices();
builder.AddGroupSearchServices();

builder.AddBlazrRenderStateServerServices();

builder.AddCategoryServices();
builder.AddProfileServices();
builder.AddChatServices();
Expand Down
1 change: 0 additions & 1 deletion src/web/Jordnaer/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@using Blazored.LocalStorage
@using Blazored.SessionStorage
@using Blazr.RenderState
@using Jordnaer
@using Jordnaer.Components
@using Jordnaer.Components.Account.Pages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Testcontainers.MsSql" Version="4.0.0" />
<PackageReference Include="Testcontainers.MsSql" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions tests/web/Jordnaer.E2E.Tests/Jordnaer.E2E.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.49.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.4.0">
<PackageReference Include="NUnit.Analyzers" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="coverlet.collector" Version="6.0.3" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions tests/web/Jordnaer.Load.Tests/Jordnaer.Load.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NBomber" Version="5.8.1" />
<PackageReference Include="NBomber.Http" Version="5.2.0" />
<PackageReference Include="NBomber" Version="5.8.2" />
<PackageReference Include="NBomber.Http" Version="5.2.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions tests/web/Jordnaer.Tests/Jordnaer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Testcontainers.Azurite" Version="4.0.0" />
<PackageReference Include="Testcontainers.MsSql" Version="4.0.0" />
<PackageReference Include="Testcontainers.Azurite" Version="4.1.0" />
<PackageReference Include="Testcontainers.MsSql" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit 0ac19b4

Please sign in to comment.