categorie fix
This commit is contained in:
44
Webshop.Application/ServiceResult.cs
Normal file
44
Webshop.Application/ServiceResult.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user