refactor(DTO): Hinzufügen des Attributs Obsolete mit der Meldung „Use DigitalData.Core.Exceptions and .Middleware“

This commit is contained in:
Developer 02 2025-05-26 15:49:22 +02:00
parent e94efc8534
commit 7621d657ac
7 changed files with 594 additions and 551 deletions

View File

@ -1,17 +1,17 @@
namespace DigitalData.Core.Application.Abstraction.DTO namespace DigitalData.Core.Application.Abstraction.DTO;
/// <summary>
/// Represents a base Data Transfer Object (DTO) with an identifier.
/// </summary>
/// <typeparam name="TId">The type of the identifier.</typeparam>
/// <param name="Id">The identifier of the DTO.</param>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public record BaseDTO<TId>(TId Id) where TId : notnull
{ {
/// <summary>
/// Represents a base Data Transfer Object (DTO) with an identifier.
/// </summary>
/// <typeparam name="TId">The type of the identifier.</typeparam>
/// <param name="Id">The identifier of the DTO.</param>
public record BaseDTO<TId>(TId Id) where TId : notnull
{
/// <summary> /// <summary>
/// Returns the hash code for this instance, based on the identifier. /// Returns the hash code for this instance, based on the identifier.
/// This override ensures that the hash code is derived consistently from the identifier. /// This override ensures that the hash code is derived consistently from the identifier.
/// </summary> /// </summary>
/// <returns>A hash code for the current object, derived from the identifier.</returns> /// <returns>A hash code for the current object, derived from the identifier.</returns>
public override int GetHashCode() => Id.GetHashCode(); public override int GetHashCode() => Id.GetHashCode();
}
} }

View File

@ -2,13 +2,14 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System.Configuration; using System.Configuration;
namespace DigitalData.Core.Application.Abstraction.DTO namespace DigitalData.Core.Application.Abstraction.DTO;
/// <summary>
/// Provides extension methods for dependency injection.
/// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static class DIExtensions
{ {
/// <summary>
/// Provides extension methods for dependency injection.
/// </summary>
public static class DIExtensions
{
/// <summary> /// <summary>
/// Adds the <see cref="CookieConsentSettings"/> to the service collection. /// Adds the <see cref="CookieConsentSettings"/> to the service collection.
/// </summary> /// </summary>
@ -17,6 +18,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <exception cref="ConfigurationErrorsException"> /// <exception cref="ConfigurationErrorsException">
/// Thrown if the 'CookieConsentSettings' section is missing or improperly configured in appsettings.json. /// Thrown if the 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.
/// </exception> /// </exception>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static IServiceCollection AddCookieConsentSettings(this IServiceCollection services) public static IServiceCollection AddCookieConsentSettings(this IServiceCollection services)
{ {
services.AddSingleton(sp => services.AddSingleton(sp =>
@ -29,5 +31,4 @@ namespace DigitalData.Core.Application.Abstraction.DTO
}); });
return services; return services;
} }
}
} }

View File

@ -1,13 +1,14 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Text; using System.Text;
namespace DigitalData.Core.Application.Abstraction.DTO namespace DigitalData.Core.Application.Abstraction.DTO;
/// <summary>
/// Provides extension methods for data transfer objects (DTOs).
/// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static class DTOExtensions
{ {
/// <summary>
/// Provides extension methods for data transfer objects (DTOs).
/// </summary>
public static class DTOExtensions
{
/// <summary> /// <summary>
/// Adds a single message to the result, if not null. /// Adds a single message to the result, if not null.
/// </summary> /// </summary>
@ -15,6 +16,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="result">The result to add the message to.</param> /// <param name="result">The result to add the message to.</param>
/// <param name="message">The message to add.</param> /// <param name="message">The message to add.</param>
/// <returns>The updated result.</returns> /// <returns>The updated result.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static T Message<T>(this T result, string? message) where T : Result public static T Message<T>(this T result, string? message) where T : Result
{ {
if(message is not null) if(message is not null)
@ -22,6 +24,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
return result; return result;
} }
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
internal static IEnumerable<T> FilterNull<T>(this IEnumerable<T?> list) internal static IEnumerable<T> FilterNull<T>(this IEnumerable<T?> list)
{ {
foreach (var item in list) foreach (var item in list)
@ -36,6 +39,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="result">The result to add the messages to.</param> /// <param name="result">The result to add the messages to.</param>
/// <param name="messages">The messages to add.</param> /// <param name="messages">The messages to add.</param>
/// <returns>The updated result.</returns> /// <returns>The updated result.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static T Message<T>(this T result, params string?[] messages) where T : Result public static T Message<T>(this T result, params string?[] messages) where T : Result
{ {
result.Messages.AddRange(messages.FilterNull()); result.Messages.AddRange(messages.FilterNull());
@ -49,6 +53,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="result">The result to add the messages to.</param> /// <param name="result">The result to add the messages to.</param>
/// <param name="messages">The collection of messages to add.</param> /// <param name="messages">The collection of messages to add.</param>
/// <returns>The updated result.</returns> /// <returns>The updated result.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static T Message<T>(this T result, IEnumerable<string?> messages) where T : Result public static T Message<T>(this T result, IEnumerable<string?> messages) where T : Result
{ {
result.Messages.AddRange(messages.FilterNull()); result.Messages.AddRange(messages.FilterNull());
@ -62,6 +67,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="result">The result to add the notice to.</param> /// <param name="result">The result to add the notice to.</param>
/// <param name="notice">The notice to add.</param> /// <param name="notice">The notice to add.</param>
/// <returns>The updated result.</returns> /// <returns>The updated result.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static T Notice<T>(this T result, Notice notice) where T : Result public static T Notice<T>(this T result, Notice notice) where T : Result
{ {
result.Notices.Add(notice); result.Notices.Add(notice);
@ -75,6 +81,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="result">The result to add the notices to.</param> /// <param name="result">The result to add the notices to.</param>
/// <param name="notices">The collection of notices to add.</param> /// <param name="notices">The collection of notices to add.</param>
/// <returns>The updated result.</returns> /// <returns>The updated result.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static T Notice<T>(this T result, IEnumerable<Notice> notices) where T : Result public static T Notice<T>(this T result, IEnumerable<Notice> notices) where T : Result
{ {
result.Notices.AddRange(notices); result.Notices.AddRange(notices);
@ -89,6 +96,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="level">The log level of the notices.</param> /// <param name="level">The log level of the notices.</param>
/// <param name="flags">The flags associated with the notices.</param> /// <param name="flags">The flags associated with the notices.</param>
/// <returns>The updated result.</returns> /// <returns>The updated result.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static T Notice<T>(this T result, LogLevel level, params Enum[] flags) where T : Result public static T Notice<T>(this T result, LogLevel level, params Enum[] flags) where T : Result
{ {
var notices = flags.Select(flag => new Notice() var notices = flags.Select(flag => new Notice()
@ -109,6 +117,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="flag">The flag associated with the notice.</param> /// <param name="flag">The flag associated with the notice.</param>
/// <param name="messages">The messages to add to the notice.</param> /// <param name="messages">The messages to add to the notice.</param>
/// <returns>The updated result.</returns> /// <returns>The updated result.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static T Notice<T>(this T result, LogLevel level, Enum flag, params string?[] messages) where T : Result public static T Notice<T>(this T result, LogLevel level, Enum flag, params string?[] messages) where T : Result
{ {
result.Notices.Add(new Notice() result.Notices.Add(new Notice()
@ -128,6 +137,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="level">The log level of the notice.</param> /// <param name="level">The log level of the notice.</param>
/// <param name="messages">The messages to add to the notice.</param> /// <param name="messages">The messages to add to the notice.</param>
/// <returns>The updated result.</returns> /// <returns>The updated result.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static T Notice<T>(this T result, LogLevel level, params string[] messages) where T : Result public static T Notice<T>(this T result, LogLevel level, params string[] messages) where T : Result
{ {
result.Notices.Add(new Notice() result.Notices.Add(new Notice()
@ -145,6 +155,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="notices">The collection of notices to check.</param> /// <param name="notices">The collection of notices to check.</param>
/// <param name="flag">The flag to check for.</param> /// <param name="flag">The flag to check for.</param>
/// <returns>True if any notice has the specified flag; otherwise, false.</returns> /// <returns>True if any notice has the specified flag; otherwise, false.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static bool HasFlag(this IEnumerable<Notice> notices, Enum flag) => notices.Any(n => n.Flag?.ToString() == flag.ToString()); public static bool HasFlag(this IEnumerable<Notice> notices, Enum flag) => notices.Any(n => n.Flag?.ToString() == flag.ToString());
/// <summary> /// <summary>
@ -153,6 +164,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="notices">The collection of notices to check.</param> /// <param name="notices">The collection of notices to check.</param>
/// <param name="flags">The flags to check for.</param> /// <param name="flags">The flags to check for.</param>
/// <returns>True if any notice has any of the specified flags; otherwise, false.</returns> /// <returns>True if any notice has any of the specified flags; otherwise, false.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static bool HasAnyFlag(this IEnumerable<Notice> notices, params Enum[] flags) => flags.Any(f => notices.HasFlag(f)); public static bool HasAnyFlag(this IEnumerable<Notice> notices, params Enum[] flags) => flags.Any(f => notices.HasFlag(f));
/// <summary> /// <summary>
@ -164,6 +176,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="Success">The function to execute if the result is successful.</param> /// <param name="Success">The function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param> /// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static I? Then<I>(this Result result, Func<I> Success) public static I? Then<I>(this Result result, Func<I> Success)
{ {
return result.IsSuccess ? Success() : default; return result.IsSuccess ? Success() : default;
@ -179,6 +192,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="Success">The function to execute if the data result is successful.</param> /// <param name="Success">The function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param> /// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static async Task<I?> ThenAsync<I>(this Result result, Func<Task<I>> SuccessAsync) public static async Task<I?> ThenAsync<I>(this Result result, Func<Task<I>> SuccessAsync)
{ {
return result.IsSuccess ? await SuccessAsync() : default; return result.IsSuccess ? await SuccessAsync() : default;
@ -192,6 +206,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="Success">The function to execute if the result is successful.</param> /// <param name="Success">The function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param> /// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static I Then<I>(this Result result, Func<I> Success, Func<List<string>, List<Notice>, I> Fail) public static I Then<I>(this Result result, Func<I> Success, Func<List<string>, List<Notice>, I> Fail)
{ {
return result.IsSuccess ? Success() : Fail(result.Messages, result.Notices); return result.IsSuccess ? Success() : Fail(result.Messages, result.Notices);
@ -205,6 +220,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="SuccessAsync">The asynchronous function to execute if the result is successful.</param> /// <param name="SuccessAsync">The asynchronous function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param> /// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static async Task<I> ThenAsync<I>(this Result result, Func<Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail) public static async Task<I> ThenAsync<I>(this Result result, Func<Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail)
{ {
return result.IsSuccess ? await SuccessAsync() : Fail(result.Messages, result.Notices); return result.IsSuccess ? await SuccessAsync() : Fail(result.Messages, result.Notices);
@ -219,6 +235,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="Success">The function to execute if the data result is successful.</param> /// <param name="Success">The function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param> /// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static I Then<T, I>(this DataResult<T> result, Func<T, I> Success, Func<List<string>, List<Notice>, I> Fail) public static I Then<T, I>(this DataResult<T> result, Func<T, I> Success, Func<List<string>, List<Notice>, I> Fail)
{ {
return result.IsSuccess ? Success(result.Data) : Fail(result.Messages, result.Notices); return result.IsSuccess ? Success(result.Data) : Fail(result.Messages, result.Notices);
@ -233,6 +250,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="SuccessAsync">The asynchronous function to execute if the data result is successful.</param> /// <param name="SuccessAsync">The asynchronous function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param> /// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static async Task<I> ThenAsync<T, I>(this DataResult<T> result, Func<T, Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail) public static async Task<I> ThenAsync<T, I>(this DataResult<T> result, Func<T, Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail)
{ {
return result.IsSuccess ? await SuccessAsync(result.Data) : Fail(result.Messages, result.Notices); return result.IsSuccess ? await SuccessAsync(result.Data) : Fail(result.Messages, result.Notices);
@ -246,6 +264,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="Success">The function to execute if the result is successful.</param> /// <param name="Success">The function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param> /// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static async Task<I> ThenAsync<I>(this Task<Result> tResult, Func<I> Success, Func<List<string>, List<Notice>, I> Fail) public static async Task<I> ThenAsync<I>(this Task<Result> tResult, Func<I> Success, Func<List<string>, List<Notice>, I> Fail)
{ {
Result result = await tResult; Result result = await tResult;
@ -260,6 +279,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="SuccessAsync">The asynchronous function to execute if the result is successful.</param> /// <param name="SuccessAsync">The asynchronous function to execute if the result is successful.</param>
/// <param name="Fail">The function to execute if the result is a failure.</param> /// <param name="Fail">The function to execute if the result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static async Task<I> ThenAsync<I>(this Task<Result> tResult, Func<Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail) public static async Task<I> ThenAsync<I>(this Task<Result> tResult, Func<Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail)
{ {
Result result = await tResult; Result result = await tResult;
@ -275,6 +295,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="Success">The function to execute if the data result is successful.</param> /// <param name="Success">The function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param> /// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static async Task<I> ThenAsync<T, I>(this Task<DataResult<T>> tResult, Func<T, I> Success, Func<List<string>, List<Notice>, I> Fail) public static async Task<I> ThenAsync<T, I>(this Task<DataResult<T>> tResult, Func<T, I> Success, Func<List<string>, List<Notice>, I> Fail)
{ {
DataResult<T> result = await tResult; DataResult<T> result = await tResult;
@ -290,6 +311,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="SuccessAsync">The asynchronous function to execute if the data result is successful.</param> /// <param name="SuccessAsync">The asynchronous function to execute if the data result is successful.</param>
/// <param name="Fail">The function to execute if the data result is a failure.</param> /// <param name="Fail">The function to execute if the data result is a failure.</param>
/// <returns>The result of the executed function.</returns> /// <returns>The result of the executed function.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static async Task<I> ThenAsync<T, I>(this Task<DataResult<T>> tResult, Func<T, Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail) public static async Task<I> ThenAsync<T, I>(this Task<DataResult<T>> tResult, Func<T, Task<I>> SuccessAsync, Func<List<string>, List<Notice>, I> Fail)
{ {
DataResult<T> result = await tResult; DataResult<T> result = await tResult;
@ -305,6 +327,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="separator">The separator string.</param> /// <param name="separator">The separator string.</param>
/// <param name="end">The ending string.</param> /// <param name="end">The ending string.</param>
/// <returns>The joined string.</returns> /// <returns>The joined string.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static string Join<T>(this IEnumerable<T> values, string start = "", string seperator = ". ", string end = ".") public static string Join<T>(this IEnumerable<T> values, string start = "", string seperator = ". ", string end = ".")
=> new StringBuilder(start).Append(string.Join(seperator, values)).Append(end).ToString(); => new StringBuilder(start).Append(string.Join(seperator, values)).Append(end).ToString();
@ -316,6 +339,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="start">The starting string for each notice.</param> /// <param name="start">The starting string for each notice.</param>
/// <param name="separator">The separator string for messages in each notice.</param> /// <param name="separator">The separator string for messages in each notice.</param>
/// <param name="end">The ending string for each notice.</param> /// <param name="end">The ending string for each notice.</param>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static void LogNotice(this ILogger logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n") public static void LogNotice(this ILogger logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n")
{ {
foreach(LogLevel level in Enum.GetValues(typeof(LogLevel))) foreach(LogLevel level in Enum.GetValues(typeof(LogLevel)))
@ -347,6 +371,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <param name="start">The starting string for each notice.</param> /// <param name="start">The starting string for each notice.</param>
/// <param name="separator">The separator string for messages in each notice.</param> /// <param name="separator">The separator string for messages in each notice.</param>
/// <param name="end">The ending string for each notice.</param> /// <param name="end">The ending string for each notice.</param>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static void LogNotice(this ILogger logger, Result result, string start = ": ", string seperator = ". ", string end = ".\n") public static void LogNotice(this ILogger logger, Result result, string start = ": ", string seperator = ". ", string end = ".\n")
=> logger.LogNotice(notices: result.Notices, start: start, seperator: seperator, end: end); => logger.LogNotice(notices: result.Notices, start: start, seperator: seperator, end: end);
@ -355,6 +380,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// </summary> /// </summary>
/// <param name="bResult">The data result to evaluate.</param> /// <param name="bResult">The data result to evaluate.</param>
/// <returns>True if the data result is true; otherwise, false.</returns> /// <returns>True if the data result is true; otherwise, false.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static bool IsRight(this DataResult<bool> bResult) => bResult.Data; public static bool IsRight(this DataResult<bool> bResult) => bResult.Data;
/// <summary> /// <summary>
@ -362,6 +388,6 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// </summary> /// </summary>
/// <param name="bResult">The data result to evaluate.</param> /// <param name="bResult">The data result to evaluate.</param>
/// <returns>True if the data result is false; otherwise, false.</returns> /// <returns>True if the data result is false; otherwise, false.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static bool IsWrong(this DataResult<bool> bResult) => !bResult.Data; public static bool IsWrong(this DataResult<bool> bResult) => !bResult.Data;
}
} }

View File

@ -1,18 +1,20 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace DigitalData.Core.Application.Abstraction.DTO namespace DigitalData.Core.Application.Abstraction.DTO;
/// <summary>
/// Represents a result of an operation that includes data, inheriting from <see cref="Result"/>.
/// </summary>
/// <typeparam name="T">The type of the data included in the result.</typeparam>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public class DataResult<T> : Result
{ {
/// <summary>
/// Represents a result of an operation that includes data, inheriting from <see cref="Result"/>.
/// </summary>
/// <typeparam name="T">The type of the data included in the result.</typeparam>
public class DataResult<T> : Result
{
/// <summary> /// <summary>
/// Gets or sets the data included in the result. This property is required. /// Gets or sets the data included in the result. This property is required.
/// It will be ignored during JSON serialization if the value is null. /// It will be ignored during JSON serialization if the value is null.
/// </summary> /// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public required T Data { get; set; } public required T Data { get; set; }
/// <summary> /// <summary>
@ -21,6 +23,6 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// </summary> /// </summary>
/// <typeparam name="I">The type of the data in the new failed result.</typeparam> /// <typeparam name="I">The type of the data in the new failed result.</typeparam>
/// <returns>A failed <see cref="DataResult{I}"/> with the current messages and notices.</returns> /// <returns>A failed <see cref="DataResult{I}"/> with the current messages and notices.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public DataResult<I> ToFail<I>() => Fail<I>().Message(Messages).Notice(Notices); public DataResult<I> ToFail<I>() => Fail<I>().Message(Messages).Notice(Notices);
}
} }

View File

@ -1,11 +1,12 @@
namespace DigitalData.Core.Application.Abstraction.DTO namespace DigitalData.Core.Application.Abstraction.DTO;
/// <summary>
/// Defines flags that indicate specific types of status or conditions in a service operation.
/// These flags help in categorizing and identifying specific circumstances or issues that may arise during execution.
/// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public enum Flag
{ {
/// <summary>
/// Defines flags that indicate specific types of status or conditions in a service operation.
/// These flags help in categorizing and identifying specific circumstances or issues that may arise during execution.
/// </summary>
public enum Flag
{
/// <summary> /// <summary>
/// Indicates a security breach or vulnerability has been detected during the service operation. /// Indicates a security breach or vulnerability has been detected during the service operation.
/// </summary> /// </summary>
@ -46,5 +47,4 @@
/// This flag is used when the specified item or condition does not exist or is unavailable. /// This flag is used when the specified item or condition does not exist or is unavailable.
/// </summary> /// </summary>
NotFound NotFound
}
} }

View File

@ -1,25 +1,28 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace DigitalData.Core.Application.Abstraction.DTO namespace DigitalData.Core.Application.Abstraction.DTO;
/// <summary>
/// Represents a notice for logging purposes, containing a flag, log level, and associated messages.
/// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public class Notice
{ {
/// <summary>
/// Represents a notice for logging purposes, containing a flag, log level, and associated messages.
/// </summary>
public class Notice
{
/// <summary> /// <summary>
/// Gets or sets an optional flag associated with the notice. /// Gets or sets an optional flag associated with the notice.
/// </summary> /// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public Enum? Flag { get; init; } = null; public Enum? Flag { get; init; } = null;
/// <summary> /// <summary>
/// Gets or sets the log level for the notice. /// Gets or sets the log level for the notice.
/// </summary> /// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public LogLevel Level { get; init; } = LogLevel.None; public LogLevel Level { get; init; } = LogLevel.None;
/// <summary> /// <summary>
/// Gets a list of messages associated with the notice. /// Gets a list of messages associated with the notice.
/// </summary> /// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public List<string> Messages { get; init; } = new(); public List<string> Messages { get; init; } = new();
}
} }

View File

@ -1,31 +1,36 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace DigitalData.Core.Application.Abstraction.DTO namespace DigitalData.Core.Application.Abstraction.DTO;
/// <summary>
/// Represents the result of an operation, containing information about its success or failure,
/// messages for the client, and notices for logging.
/// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public class Result
{ {
/// <summary>
/// Represents the result of an operation, containing information about its success or failure,
/// messages for the client, and notices for logging.
/// </summary>
public class Result
{
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the operation was successful. /// Gets or sets a value indicating whether the operation was successful.
/// </summary> /// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public bool IsSuccess { get; set; } = false; public bool IsSuccess { get; set; } = false;
/// <summary> /// <summary>
/// Gets a value indicating whether the operation failed. /// Gets a value indicating whether the operation failed.
/// </summary> /// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public bool IsFailed => !IsSuccess; public bool IsFailed => !IsSuccess;
/// <summary> /// <summary>
/// Gets a list of messages intended for the client. /// Gets a list of messages intended for the client.
/// </summary> /// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public List<string> Messages { get; init; } = new(); public List<string> Messages { get; init; } = new();
/// <summary> /// <summary>
/// Gets a list of notices intended for logging purposes. This property is ignored during JSON serialization. /// Gets a list of notices intended for logging purposes. This property is ignored during JSON serialization.
/// </summary> /// </summary>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
[JsonIgnore] [JsonIgnore]
public List<Notice> Notices = new(); public List<Notice> Notices = new();
@ -35,6 +40,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <typeparam name="T">The type of the data.</typeparam> /// <typeparam name="T">The type of the data.</typeparam>
/// <param name="data">The data to include in the result.</param> /// <param name="data">The data to include in the result.</param>
/// <returns>A new <see cref="DataResult{T}"/> instance.</returns> /// <returns>A new <see cref="DataResult{T}"/> instance.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public DataResult<T> Data<T>(T data) => new() public DataResult<T> Data<T>(T data) => new()
{ {
IsSuccess = IsSuccess, IsSuccess = IsSuccess,
@ -48,6 +54,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// </summary> /// </summary>
/// <param name="flag">The flag to check.</param> /// <param name="flag">The flag to check.</param>
/// <returns>True if any notice has the specified flag; otherwise, false.</returns> /// <returns>True if any notice has the specified flag; otherwise, false.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public bool HasFlag(Enum flag) => Notices.Any(n => n.Flag?.ToString() == flag.ToString()); public bool HasFlag(Enum flag) => Notices.Any(n => n.Flag?.ToString() == flag.ToString());
/// <summary> /// <summary>
@ -55,18 +62,21 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// </summary> /// </summary>
/// <param name="flags">The flags to check.</param> /// <param name="flags">The flags to check.</param>
/// <returns>True if any notice has any of the specified flags; otherwise, false.</returns> /// <returns>True if any notice has any of the specified flags; otherwise, false.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public bool HasAnyFlag(params Enum[] flags) => flags.Any(HasFlag); public bool HasAnyFlag(params Enum[] flags) => flags.Any(HasFlag);
/// <summary> /// <summary>
/// Creates a new successful <see cref="Result"/>. /// Creates a new successful <see cref="Result"/>.
/// </summary> /// </summary>
/// <returns>A new successful <see cref="Result"/>.</returns> /// <returns>A new successful <see cref="Result"/>.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static Result Success() => new() { IsSuccess = true }; public static Result Success() => new() { IsSuccess = true };
/// <summary> /// <summary>
/// Creates a new failed <see cref="Result"/>. /// Creates a new failed <see cref="Result"/>.
/// </summary> /// </summary>
/// <returns>A new failed <see cref="Result"/>.</returns> /// <returns>A new failed <see cref="Result"/>.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static Result Fail() => new() { IsSuccess = false }; public static Result Fail() => new() { IsSuccess = false };
/// <summary> /// <summary>
@ -75,6 +85,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// <typeparam name="T">The type of the data.</typeparam> /// <typeparam name="T">The type of the data.</typeparam>
/// <param name="data">The data to include in the result.</param> /// <param name="data">The data to include in the result.</param>
/// <returns>A new successful <see cref="DataResult{T}"/> with the specified data.</returns> /// <returns>A new successful <see cref="DataResult{T}"/> with the specified data.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
public static DataResult<T> Success<T>(T data) => new() public static DataResult<T> Success<T>(T data) => new()
{ {
IsSuccess = true, IsSuccess = true,
@ -86,6 +97,7 @@ namespace DigitalData.Core.Application.Abstraction.DTO
/// </summary> /// </summary>
/// <typeparam name="T">The type of the data.</typeparam> /// <typeparam name="T">The type of the data.</typeparam>
/// <returns>A new failed <see cref="DataResult{T}"/> with no data.</returns> /// <returns>A new failed <see cref="DataResult{T}"/> with no data.</returns>
[Obsolete("Use DigitalData.Core.Exceptions and .Middleware")]
#pragma warning disable CS8601 // Possible null reference assignment. #pragma warning disable CS8601 // Possible null reference assignment.
public static DataResult<T> Fail<T>() => new() public static DataResult<T> Fail<T>() => new()
{ {
@ -93,5 +105,4 @@ namespace DigitalData.Core.Application.Abstraction.DTO
Data = default Data = default
}; };
#pragma warning restore CS8601 // Possible null reference assignment. #pragma warning restore CS8601 // Possible null reference assignment.
}
} }