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

Fix compiler warnings related to nullability in Messages module #502

Merged
merged 75 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
10faa71
chore: add nullable enable property group
HunorTotBagi Jan 19, 2024
c4d07a8
chore: fix formatting issues
HunorTotBagi Jan 19, 2024
01d8cd7
refactor: wip
HunorTotBagi Jan 19, 2024
4d81777
refactor: wip
HunorTotBagi Jan 22, 2024
59e61f8
Merge remote-tracking branch 'origin/main' into fix-messages-related-…
HunorTotBagi Jan 22, 2024
e6104f8
Merge branch 'fix-messages-related-issues' of https://github.com/nmsh…
HunorTotBagi Jan 22, 2024
ef7d04e
fix: revert to fix admin UI Checks
HunorTotBagi Jan 22, 2024
c886ac4
refactor: declare properties as nullable
HunorTotBagi Jan 22, 2024
297deb5
refactor: fix non-nullable property for Body
HunorTotBagi Jan 23, 2024
e7d40bc
fix: compile error
HunorTotBagi Jan 23, 2024
65b2354
fix: formatting
HunorTotBagi Jan 23, 2024
c5a403b
refactor: fix non-nullable propert for EncryptedKey
HunorTotBagi Jan 23, 2024
ce20da7
refactor: fix non-nullable property for Id
HunorTotBagi Jan 23, 2024
8892593
refactor: declared queueName as nullable
HunorTotBagi Jan 23, 2024
a488890
refactor: solve non-nullable property for MessageDTO
HunorTotBagi Jan 23, 2024
e8d568a
refactor: declare properties for DbOptions nullable
HunorTotBagi Jan 23, 2024
e60ca00
refactor: add nullable
HunorTotBagi Jan 23, 2024
011060e
chore: remove empty line
HunorTotBagi Jan 23, 2024
4a15577
refactor: make Address and EncryptedKey required
HunorTotBagi Jan 24, 2024
5bce550
refactor: make Id required
HunorTotBagi Jan 24, 2024
3baf41a
refactor: remove null suppression for Id
HunorTotBagi Jan 24, 2024
7c5fc02
refactor: remove null check for EncryptedKey since it is required
HunorTotBagi Jan 24, 2024
7e65a4c
refactor: remove redundant ! operator
HunorTotBagi Jan 24, 2024
ec13b23
refactor: make MessageId required
HunorTotBagi Jan 24, 2024
b666127
refactor: make Id required
HunorTotBagi Jan 24, 2024
1addfab
refactor: make MessageId required
HunorTotBagi Jan 24, 2024
ab4feba
refactor: make CreatedBy required
HunorTotBagi Jan 24, 2024
f753af9
refactor: make CreatedByDevice required
HunorTotBagi Jan 24, 2024
9d8b492
refactor: make Body required
HunorTotBagi Jan 24, 2024
8ff7faf
refactor: make Attachments required
HunorTotBagi Jan 24, 2024
3b045d7
refactor: make Recipients required
HunorTotBagi Jan 24, 2024
0662716
refactor: make Address required
HunorTotBagi Jan 24, 2024
af9e419
refactor: make EncryptedKey required
HunorTotBagi Jan 24, 2024
9bfe53b
chore: move property group to the top of the file
HunorTotBagi Jan 24, 2024
e570381
refactor: make Id required
HunorTotBagi Jan 24, 2024
6b2803d
refactor: set From and To to default!
HunorTotBagi Jan 24, 2024
34757aa
refactor: initialize Provider and DbConnectionnString with null!
HunorTotBagi Jan 24, 2024
e94bd29
refactor: make Body required and remove null check
HunorTotBagi Jan 24, 2024
97a5607
refactor: remove redundant ! operator
HunorTotBagi Jan 24, 2024
1c792fd
refactor: remove When check since the expression is always true
HunorTotBagi Jan 24, 2024
7b395f9
refactor: remove nullable and redundant ! since it doesn't cause an i…
HunorTotBagi Jan 24, 2024
a14099a
refactor: add extra logic on HasFrom and HasTo
HunorTotBagi Jan 24, 2024
915c8ae
refactor: suppress the null warning
HunorTotBagi Jan 25, 2024
26e603d
refactor: apply only Equals
HunorTotBagi Jan 25, 2024
f79d6fe
Merge main into fix-messages-related-issues
github-actions[bot] Jan 26, 2024
a42a9f5
ci: trigger pipelines
HunorTotBagi Jan 26, 2024
b227d5c
Merge branch 'fix-messages-related-issues' of https://github.com/nmsh…
HunorTotBagi Jan 26, 2024
8b99f65
Merge main into fix-messages-related-issues
github-actions[bot] Jan 29, 2024
68ab9c8
Merge main into fix-messages-related-issues
github-actions[bot] Jan 29, 2024
cb0431f
Merge main into fix-messages-related-issues
github-actions[bot] Jan 30, 2024
ae0e7d2
Merge main into fix-messages-related-issues
github-actions[bot] Feb 5, 2024
c61126d
Merge main into fix-messages-related-issues
github-actions[bot] Feb 5, 2024
2aff3d7
Merge main into fix-messages-related-issues
github-actions[bot] Feb 6, 2024
3138d60
Merge main into fix-messages-related-issues
github-actions[bot] Feb 9, 2024
5719275
Merge main into fix-messages-related-issues
github-actions[bot] Feb 9, 2024
d4e02ad
Merge main into fix-messages-related-issues
github-actions[bot] Feb 9, 2024
5d106f0
Merge main into fix-messages-related-issues
github-actions[bot] Feb 9, 2024
9035bd6
Merge main into fix-messages-related-issues
github-actions[bot] Feb 9, 2024
28c42ea
Merge branch 'main' into fix-messages-related-issues
mergify[bot] Feb 9, 2024
c9746de
Merge branch 'main' into fix-messages-related-issues
mergify[bot] Feb 12, 2024
9fde366
Merge branch 'main' into fix-messages-related-issues
tnotheis Feb 12, 2024
81740b3
chore: fix nullability issues
tnotheis Feb 12, 2024
07372be
chore: remove unused setter
tnotheis Feb 12, 2024
63dfadd
chore: add comments for ef core constructors
tnotheis Feb 12, 2024
1341b76
chore: add comments to ef core constructor
tnotheis Feb 12, 2024
90ca7b9
chore: make GetMessageQuery.NoBody required
tnotheis Feb 14, 2024
8f78fe9
Merge branch 'main' into fix-messages-related-issues
mergify[bot] Feb 14, 2024
13a983d
chore: enable nullable for Messags.Application.Tests
tnotheis Feb 14, 2024
a8fd2ee
Merge branch 'main' into fix-messages-related-issues
mergify[bot] Feb 14, 2024
50b68b2
Merge branch 'main' into fix-messages-related-issues
mergify[bot] Feb 16, 2024
fdf2cc5
Merge branch 'main' into fix-messages-related-issues
mergify[bot] Feb 19, 2024
9a038b0
Merge branch 'main' into fix-messages-related-issues
mergify[bot] Feb 19, 2024
004032a
Merge branch 'fix-messages-related-issues' of github.com:nmshd/backbo…
tnotheis Feb 19, 2024
8da3a5d
chore: remove redundant using directives
tnotheis Feb 19, 2024
67d7a02
chore: make properties required
tnotheis Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Backbone.Modules.Messages.Application.Extensions;

public static class RecipientInformationICollectionExtensions
{
public static RecipientInformation FirstWithIdOrDefault(this IReadOnlyCollection<RecipientInformation> query, IdentityAddress address)
public static RecipientInformation? FirstWithIdOrDefault(this IReadOnlyCollection<RecipientInformation> query, IdentityAddress address)
{
return query.FirstOrDefault(r => r.Address == address);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Backbone.Modules.Messages.Application.Infrastructure.EventBus;

public interface IMessagesEventBus : IEventBus
{
}
public interface IMessagesEventBus : IEventBus;
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class BlobOptions
{
public string RootFolder { get; set; }
public string? RootFolder { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Backbone.Modules.Messages.Application.Infrastructure.Persistence.Repository;

#nullable enable
public interface IRelationshipsRepository
{
Task<RelationshipId?> GetIdOfRelationshipBetweenSenderAndRecipient(IdentityAddress identityA, IdentityAddress identityB);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
</ItemGroup>
Expand All @@ -9,4 +13,5 @@
<ProjectReference Include="..\..\..\..\BuildingBlocks\src\BuildingBlocks.Application\BuildingBlocks.Application.csproj" />
<ProjectReference Include="..\Messages.Domain\Messages.Domain.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ public class SendMessageCommand : IRequest<SendMessageResponse>
{
public ICollection<SendMessageCommandRecipientInformation> Recipients { get; set; } = new List<SendMessageCommandRecipientInformation>();
public DateTime? DoNotSendBefore { get; set; }
public byte[] Body { get; set; }
public required byte[] Body { get; set; }
public ICollection<SendMessageCommandAttachment> Attachments { get; set; } = new List<SendMessageCommandAttachment>();
}

public class SendMessageCommandRecipientInformation
{
public IdentityAddress Address { get; set; }
public byte[] EncryptedKey { get; set; }
public required IdentityAddress Address { get; set; }
public required byte[] EncryptedKey { get; set; }
}

public class SendMessageCommandAttachment
{
public string Id { get; set; }
public required string Id { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public SendMessageCommandValidator()
.SetValidator(new SendMessageCommandRecipientInformationValidator()));

RuleFor(m => m.Recipients.Count)
.InclusiveBetween(1, 50).When(m => m.Recipients != null).WithErrorCode(GenericApplicationErrors.Validation.InvalidPropertyValue().Code);
.InclusiveBetween(1, 50).WithErrorCode(GenericApplicationErrors.Validation.InvalidPropertyValue().Code);

RuleFor(m => m.Body).DetailedNotNull().NumberOfBytes(1, 10.Mebibytes());

Expand All @@ -29,7 +29,7 @@ public SendMessageCommandValidator()
.SetValidator(new SendMessageCommandAttachmentValidator()));

RuleFor(m => m.Attachments.Count)
.InclusiveBetween(0, 20).When(m => m.Attachments != null).WithErrorCode(GenericApplicationErrors.Validation.InvalidPropertyValue().Code);
.InclusiveBetween(0, 20).WithErrorCode(GenericApplicationErrors.Validation.InvalidPropertyValue().Code);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Backbone.Modules.Messages.Application.Messages.Commands.SendMessage;

public class SendMessageResponse : IMapTo<Message>
{
public MessageId Id { get; set; }
public required MessageId Id { get; set; }
public DateTime CreatedAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Backbone.Modules.Messages.Application.Messages.DTOs;

public class AttachmentDTO : IMapTo<Attachment>
{
public string Id { get; set; }
public required string Id { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace Backbone.Modules.Messages.Application.Messages.DTOs;

public class MessageDTO : IMapTo<Message>
{
public MessageId Id { get; set; }
public required MessageId Id { get; set; }

public DateTime CreatedAt { get; set; }
public IdentityAddress CreatedBy { get; set; }
public DeviceId CreatedByDevice { get; set; }
public required IdentityAddress CreatedBy { get; set; }
public required DeviceId CreatedByDevice { get; set; }

public DateTime? DoNotSendBefore { get; set; }
public byte[] Body { get; set; }
public required byte[] Body { get; set; }

public List<AttachmentDTO> Attachments { get; set; }
public List<RecipientInformationDTO> Recipients { get; set; }
public required List<AttachmentDTO> Attachments { get; set; }
public required List<RecipientInformationDTO> Recipients { get; set; }

public void PrepareForActiveIdentity(IdentityAddress activeIdentity)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Backbone.Modules.Messages.Application.Messages.DTOs;

public class RecipientInformationDTO : IMapTo<RecipientInformation>
{
public IdentityAddress Address { get; set; }
public byte[] EncryptedKey { get; set; }
public required IdentityAddress Address { get; set; }
public required byte[] EncryptedKey { get; set; }
public DateTime? ReceivedAt { get; set; }
public DeviceId ReceivedByDevice { get; set; }
public DeviceId? ReceivedByDevice { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Backbone.Modules.Messages.Application.Messages.Queries.GetMessage;

public class GetMessageQuery : IRequest<MessageDTO>
{
public MessageId Id { get; init; }
public bool NoBody { get; init; }
public required MessageId Id { get; init; }
public required bool NoBody { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
namespace Backbone.Modules.Messages.Application.Messages.Queries.ListMessages;

// ReSharper disable once UnusedMember.Global
public class ListMessagesQueryValidator : AbstractValidator<ListMessagesQuery>
{
public ListMessagesQueryValidator() { }
}
public class ListMessagesQueryValidator : AbstractValidator<ListMessagesQuery>;
12 changes: 8 additions & 4 deletions Modules/Messages/src/Messages.Common/Messages.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.9.0" />
</ItemGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.9.0" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions Modules/Messages/src/Messages.Common/Range.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ public Range(T from, T to)
To = to;
}

public T From { get; set; }
public T To { get; set; }
public T From { get; set; } = default!;
public T To { get; set; } = default!;

public bool HasFrom()
{
return !From.Equals(default(T));
return Equals(From, default(T));
}

public bool HasTo()
{
return !To.Equals(default(T));
return Equals(To, default(T));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ namespace Backbone.Modules.Messages.Domain.Entities;

public class Attachment
{
#pragma warning disable CS8618
public Attachment(FileId id)
#pragma warning restore CS8618
{
Id = id;
MessageId = null!; // we just assign null to satisfy the compiler; it will be set by EF Core
}

public FileId Id { get; set; }
public MessageId MessageId { get; set; }
public Message Message { get; set; }
}
14 changes: 11 additions & 3 deletions Modules/Messages/src/Messages.Domain/Entities/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ namespace Backbone.Modules.Messages.Domain.Entities;

public class Message : IIdentifiable<MessageId>
{
#pragma warning disable CS8618
private Message() { }
#pragma warning restore CS8618
// ReSharper disable once UnusedMember.Local
private Message()
{
// This constructor is for EF Core only; initializing the properties with null is therefore not a problem
Id = null!;
CreatedBy = null!;
CreatedByDevice = null!;
Body = null!;
Attachments = null!;
Recipients = null!;
}

public Message(IdentityAddress createdBy, DeviceId createdByDevice, DateTime? doNotSendBefore, byte[] body, IEnumerable<Attachment> attachments, IEnumerable<RecipientInformation> recipients)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ namespace Backbone.Modules.Messages.Domain.Entities;

public class RecipientInformation
{
#pragma warning disable CS8618
private RecipientInformation() { }
#pragma warning restore CS8618
// ReSharper disable once UnusedMember.Local
private RecipientInformation()
{
// This constructor is for EF Core only; initializing the properties with null is therefore not a problem
Address = null!;
EncryptedKey = null!;
RelationshipId = null!;
MessageId = null!;
}

#pragma warning disable CS8618
public RecipientInformation(IdentityAddress address, RelationshipId relationshipId, byte[] encryptedKey)
#pragma warning restore CS8618
{
Address = address;
RelationshipId = relationshipId;
EncryptedKey = encryptedKey;
MessageId = null!; // we just assign null to satisfy the compiler; it will be set by EF Core
}

public IdentityAddress Address { get; }
Expand All @@ -28,10 +33,9 @@ public RecipientInformation(IdentityAddress address, RelationshipId relationship

public void FetchedMessage(DeviceId fetchedByDevice)
{
if (!ReceivedAt.HasValue)
{
ReceivedAt = SystemTime.UtcNow;
ReceivedByDevice = fetchedByDevice;
}
if (ReceivedAt.HasValue) return;

ReceivedAt = SystemTime.UtcNow;
ReceivedByDevice = fetchedByDevice;
}
}
15 changes: 11 additions & 4 deletions Modules/Messages/src/Messages.Domain/Entities/Relationship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ namespace Backbone.Modules.Messages.Domain.Entities;

public class Relationship
{
#pragma warning disable CS8618
private Relationship() { }
#pragma warning restore CS8618
// ReSharper disable once UnusedMember.Local
private Relationship()
{
// This constructor is for EF Core only; initializing the properties with null is therefore not a problem
Id = null!;
From = null!;
To = null!;
CreatedAt = default;
Status = default;
}

public RelationshipId Id { get; }

Expand All @@ -16,7 +23,7 @@ private Relationship() { }

public DateTime CreatedAt { get; }

public RelationshipStatus Status { get; private set; }
public RelationshipStatus Status { get; }
}

public enum RelationshipStatus
Expand Down
8 changes: 4 additions & 4 deletions Modules/Messages/src/Messages.Domain/Messages.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\BuildingBlocks\src\DevelopmentKit.Identity\DevelopmentKit.Identity.csproj" />
<ProjectReference Include="..\..\..\..\BuildingBlocks\src\Tooling\Tooling.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Messages.Infrastructure\Messages.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Messages.Infrastructure\Messages.Infrastructure.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Messages.Infrastructure\Messages.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Messages.Infrastructure\Messages.Infrastructure.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Backbone.Modules.Messages.Infrastructure.EventBus;
public class MessagesEventBusRabbitMq : EventBusRabbitMq, IMessagesEventBus
{
public MessagesEventBusRabbitMq(IRabbitMqPersistentConnection persistentConnection, ILogger<EventBusRabbitMq> logger, ILifetimeScope autofac, IEventBusSubscriptionsManager subsManager, HandlerRetryBehavior handlerRetryBehavior, string queueName = null) : base(persistentConnection, logger, autofac, subsManager, handlerRetryBehavior, queueName)
public MessagesEventBusRabbitMq(IRabbitMqPersistentConnection persistentConnection, ILogger<EventBusRabbitMq> logger, ILifetimeScope autofac, IEventBusSubscriptionsManager subsManager, HandlerRetryBehavior handlerRetryBehavior, string? queueName = null) : base(persistentConnection, logger, autofac, subsManager, handlerRetryBehavior, queueName)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
Expand All @@ -12,4 +16,5 @@
<ProjectReference Include="..\Messages.Application\Messages.Application.csproj" />
<ProjectReference Include="..\Messages.Domain\Messages.Domain.csproj" />
</ItemGroup>

</Project>
Loading