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

Add soft deletable interface #60

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions Source/BSN.Commons/BSN.Commons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Apache.NMS" Version="1.8.0" />
Reza-Noei marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="Apache.NMS.ActiveMQ" Version="1.7.2" />
<PackageReference Include="Apache.NMS" Version="2.1.0" />
<PackageReference Include="Apache.NMS.ActiveMQ" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.32" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.32" />
<PackageReference Include="Confluent.Kafka" Version="2.2.0" />
<PackageReference Include="Confluent.Kafka" Version="2.3.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Polly" Version="8.0.0" />
<PackageReference Include="RabbitMQ.Client" Version="6.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polly" Version="8.0.0" />
<PackageReference Include="RabbitMQ.Client" Version="6.6.0" />
<PackageReference Include="System.Text.Json" Version="6.0.6" />
Expand Down
39 changes: 39 additions & 0 deletions Source/BSN.Commons/ISoftDeletable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

namespace BSN.Commons
{
/// <summary>
/// Provides a mechanism for soft deletion.
///
/// Soft deletion means that this object is not completely destroyed, but it goes in a deleted state,
/// and you can ask this object if you are deleted or not?
/// </summary>
public interface ISoftDeletable
{
/// <summary>
/// Shows the time of deletion.
///
/// Time based on UTC.
/// </summary>
/// <remarks>
/// If this object is not deleted, this property returns <see cref="DateTime.MinValue"/>.
/// </remarks>
DateTime DeletedAt
Reza-Noei marked this conversation as resolved.
Show resolved Hide resolved
{
get;
}

/// <summary>
/// Shows if this object is deleted or not.
/// </summary>
bool IsDeleted
{
get;
}

/// <summary>
/// Delete this object.
/// </summary>
void SoftDelete();
}
}
31 changes: 31 additions & 0 deletions Source/BSN.Commons/SoftDeletableBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BSN.Commons
{
/// <inheritdoc/>
public abstract class SoftDeletableBase : ISoftDeletable
{
/// <inheritdoc/>
public DateTime DeletedAt
{
get;
private set;
}

/// <inheritdoc/>
public bool IsDeleted => DeletedAt != DateTime.MinValue;

/// <inheritdoc/>
public virtual void SoftDelete()
{
if (DeletedAt != DateTime.MinValue)
{
throw new InvalidOperationException("This object is already deleted.");
}

DeletedAt = DateTime.UtcNow;
}
}
}
Loading