categorie fix

This commit is contained in:
Tizian.Breuch
2025-08-29 09:37:06 +02:00
parent 4279e8186b
commit 6e6f38397b
6 changed files with 207 additions and 117 deletions

View File

@@ -0,0 +1,44 @@
// src/Webshop.Application/ServiceResult.cs
namespace Webshop.Application
{
public enum ServiceResultType
{
Success,
NotFound,
InvalidInput,
Conflict,
Failure
}
public class ServiceResult
{
public ServiceResultType Type { get; }
public string? ErrorMessage { get; }
protected ServiceResult(ServiceResultType type, string? errorMessage = null)
{
Type = type;
ErrorMessage = errorMessage;
}
public static ServiceResult Ok() => new ServiceResult(ServiceResultType.Success);
public static ServiceResult<T> Ok<T>(T value) => new ServiceResult<T>(value, ServiceResultType.Success);
// Allgemeine Fail-Methode
public static ServiceResult Fail(ServiceResultType type, string errorMessage) => new ServiceResult(type, errorMessage);
// Generische Fail-Methode
public static ServiceResult<T> Fail<T>(ServiceResultType type, string errorMessage) => new ServiceResult<T>(default, type, errorMessage);
}
public class ServiceResult<T> : ServiceResult
{
public T? Value { get; }
protected internal ServiceResult(T? value, ServiceResultType type, string? errorMessage = null)
: base(type, errorMessage)
{
Value = value;
}
}
}