SHA256
GuestLog - Moved Enums
- Enums moved to Enum folder (by type). - ResultCode class changed to enum to ensure type safety in results.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Somnia.GuestLog.Enums.Services;
|
||||
|
||||
namespace Somnia.GuestLog.Models.Configuration;
|
||||
|
||||
public class AddressQueryConfig
|
||||
@@ -5,18 +7,10 @@ public class AddressQueryConfig
|
||||
public const string SectionName = "AddressQuery";
|
||||
|
||||
public bool EnableAddressQuery { get; set; }
|
||||
public AddressQueryProviderEnum? Provider { get; set; }
|
||||
public AddressQueryProvider? Provider { get; set; }
|
||||
public string? ServiceURL { get; set; }
|
||||
public string? ApiKey { get; set; }
|
||||
public string? UserAgent { get; set; }
|
||||
public string? ResultLang { get; set; }
|
||||
|
||||
|
||||
public enum AddressQueryProviderEnum
|
||||
{
|
||||
Nominatim,
|
||||
GoogleApiV4
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
using Somnia.GuestLog.Enums.Services;
|
||||
|
||||
namespace Somnia.GuestLog.Models.DTOs;
|
||||
|
||||
public sealed record Result(bool IsSuccess, string ResultCode, params object[]? Context)
|
||||
public sealed record Result(bool IsSuccess, ResultCode ResultCode, params object[]? Context)
|
||||
{
|
||||
public static Result Ok() => new(IsSuccess: true, ResultCode: Models.ResultCode.Ok, Context: null);
|
||||
public static Result Ok() => new(IsSuccess: true, ResultCode: ResultCode.Ok, Context: null);
|
||||
|
||||
public static Result Fail(string resultCode) => new(IsSuccess: false, resultCode, Context: null);
|
||||
public static Result FailWithContext(string resultCode, params object[] context)
|
||||
public static Result Fail(ResultCode resultCode) => new(IsSuccess: false, resultCode, Context: null);
|
||||
public static Result FailWithContext(ResultCode resultCode, params object[] context)
|
||||
=> new(IsSuccess: false, resultCode, context);
|
||||
public static Result FailUnknownError()
|
||||
=> new(IsSuccess: false, ResultCode: Models.ResultCode.UnknownError, Context: null);
|
||||
=> new(IsSuccess: false, ResultCode: ResultCode.UnknownError, Context: null);
|
||||
|
||||
public bool IsUnknownError => !IsSuccess && ResultCode == Models.ResultCode.UnknownError;
|
||||
public bool IsUnknownError => !IsSuccess && ResultCode == ResultCode.UnknownError;
|
||||
}
|
||||
|
||||
public sealed record Result<T>(bool IsSuccess, T? Value, string ResultCode, params object[]? Context)
|
||||
public sealed record Result<T>(bool IsSuccess, T? Value, ResultCode ResultCode, params object[]? Context)
|
||||
{
|
||||
public static Result<T> Ok(T value) => new(IsSuccess: true, value, ResultCode: Models.ResultCode.Ok, Context: null);
|
||||
public static Result<T> Fail(string resultCode) => new(IsSuccess: false, Value: default, resultCode, Context: null);
|
||||
public static Result<T> FailWithContext(string resultCode, params object[] context)
|
||||
public static Result<T> Ok(T value) => new(IsSuccess: true, value, ResultCode: ResultCode.Ok, Context: null);
|
||||
public static Result<T> Fail(ResultCode resultCode) => new(IsSuccess: false, Value: default, resultCode, Context: null);
|
||||
public static Result<T> FailWithContext(ResultCode resultCode, params object[] context)
|
||||
=> new(IsSuccess: false, Value: default, resultCode, context);
|
||||
|
||||
public bool IsUnknownError => !IsSuccess && ResultCode == Models.ResultCode.UnknownError;
|
||||
public bool IsUnknownError => !IsSuccess && ResultCode == ResultCode.UnknownError;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Somnia.GuestLog.Models;
|
||||
|
||||
public static class ResultCode
|
||||
{
|
||||
public const string Ok = "Ok";
|
||||
public const string UnknownError = "UnknownError";
|
||||
public const string FailedValidation = "FailedValidation";
|
||||
public const string NotFound = "NotFound";
|
||||
|
||||
public const string GuestCurrentlyInStay = "GuestCurrentlyInStay";
|
||||
}
|
||||
Reference in New Issue
Block a user