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:
2026-08-25 15:18:02 +02:00
parent b18bd7caa6
commit 4f22cd4541
13 changed files with 51 additions and 45 deletions
@@ -16,4 +16,4 @@
@using Somnia.GuestLog.Components.Forms
@using Somnia.GuestLog.Components.Controls
@using Somnia.GuestLog.Resources
@using MessageKind = Somnia.GuestLog.Services.IUserMessageService.MessageKind;
@using Somnia.GuestLog.Enums.UI
@@ -0,0 +1,7 @@
namespace Somnia.GuestLog.Enums.Services;
public enum AddressQueryProvider
{
Nominatim,
GoogleApiV4
}
@@ -0,0 +1,10 @@
namespace Somnia.GuestLog.Enums.Services;
public enum ResultCode
{
Ok,
UnknownError,
FailedValidation,
NotFound,
GuestCurrentlyInStay,
}
@@ -1,4 +1,4 @@
namespace Somnia.GuestLog.Components.Forms;
namespace Somnia.GuestLog.Enums.UI;
public enum FormMode
{
@@ -0,0 +1,6 @@
namespace Somnia.GuestLog.Enums.UI;
public enum MessageKind
{
Info, Warning, Error, Success, Normal
}
@@ -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
}
}
+13 -11
View File
@@ -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;
}
-11
View File
@@ -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";
}
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Options;
using Somnia.GuestLog.Enums.Services;
using Somnia.GuestLog.Models.Configuration;
using Somnia.GuestLog.Utils.DI;
@@ -11,8 +12,8 @@ public class ConfigFileAddressQueryFactory(
{
public static void RegisterFactoryItems(IServiceCollection services)
{
services.AddKeyedTransient<IAddressQueryService, NominatimAddressQueryService>(AddressQueryConfig.AddressQueryProviderEnum.Nominatim);
services.AddKeyedTransient<IAddressQueryService, GoogleApiAddressQueryService>(AddressQueryConfig.AddressQueryProviderEnum.GoogleApiV4);
services.AddKeyedTransient<IAddressQueryService, NominatimAddressQueryService>(AddressQueryProvider.Nominatim);
services.AddKeyedTransient<IAddressQueryService, GoogleApiAddressQueryService>(AddressQueryProvider.GoogleApiV4);
}
public IAddressQueryService GetService()
@@ -1,5 +1,6 @@
using FluentValidation;
using Microsoft.EntityFrameworkCore;
using Somnia.GuestLog.Enums.Services;
using Somnia.GuestLog.Infrastructure;
using Somnia.GuestLog.Models;
using Somnia.GuestLog.Models.DTOs;
@@ -1,3 +1,4 @@
using Somnia.GuestLog.Enums.UI;
using Somnia.GuestLog.Models.DTOs;
namespace Somnia.GuestLog.Services;
@@ -8,10 +9,4 @@ public interface IUserMessageService
public void ShowResult(Result resultDto);
public void ShowResultWithMessage(Result resultDto, string message);
public enum MessageKind
{
Info, Warning, Error, Success, Normal
}
}
@@ -1,5 +1,6 @@
using FluentValidation;
using Microsoft.EntityFrameworkCore;
using Somnia.GuestLog.Enums.Services;
using Somnia.GuestLog.Infrastructure;
using Somnia.GuestLog.Models;
using Somnia.GuestLog.Models.DTOs;
@@ -1,9 +1,9 @@
using Microsoft.Extensions.Localization;
using MudBlazor;
using Somnia.GuestLog.Models;
using Somnia.GuestLog.Enums.Services;
using Somnia.GuestLog.Enums.UI;
using Somnia.GuestLog.Models.DTOs;
using Somnia.GuestLog.Resources;
using MessageKind = Somnia.GuestLog.Services.IUserMessageService.MessageKind;
namespace Somnia.GuestLog.Services;
@@ -59,9 +59,9 @@ public class UserMessageService(
snackbar.Add(message: msg, severity: GetSnackbarSeveryForMessageKind(kind));
}
private string GetMsgForResultCode(string resultCode)
private string GetMsgForResultCode(ResultCode resultCode)
{
return _localizer[$"resultCode.{resultCode}"];
return _localizer[$"resultCode.{Enum.GetName(resultCode)}"];
}
private static string GetFormatedMessage(string template, params object[]? parameters)