From 61dc0a8bc419c7363daf936407ffbc2916602189 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 2 Nov 2024 01:05:24 +0300 Subject: [PATCH] feat: add converter for two factor --- .../TwoFactorAuthenticationConverter.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Endpoint/Common/MapperDto/TwoFactorAuthenticationConverter.cs diff --git a/Endpoint/Common/MapperDto/TwoFactorAuthenticationConverter.cs b/Endpoint/Common/MapperDto/TwoFactorAuthenticationConverter.cs new file mode 100644 index 0000000..4086790 --- /dev/null +++ b/Endpoint/Common/MapperDto/TwoFactorAuthenticationConverter.cs @@ -0,0 +1,24 @@ +using Mirea.Api.Dto.Common; +using Mirea.Api.Security.Common.Domain; +using System; + +namespace Mirea.Api.Endpoint.Common.MapperDto; + +public static class TwoFactorAuthenticationConverter +{ + public static TwoFactorAuthentication ConvertToDto(this TwoFactorAuthenticator authenticator) => + authenticator switch + { + TwoFactorAuthenticator.None => TwoFactorAuthentication.None, + TwoFactorAuthenticator.Totp => TwoFactorAuthentication.TotpRequired, + _ => throw new ArgumentOutOfRangeException(nameof(authenticator), authenticator, null) + }; + + public static TwoFactorAuthenticator ConvertFromDto(this TwoFactorAuthentication authentication) => + authentication switch + { + TwoFactorAuthentication.None => TwoFactorAuthenticator.None, + TwoFactorAuthentication.TotpRequired => TwoFactorAuthenticator.Totp, + _ => throw new ArgumentOutOfRangeException(nameof(authentication), authentication, null) + }; +} \ No newline at end of file