From 17e20fee2e2573d3437e6a68476a24be705e025f Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Thu, 4 Jul 2024 23:52:25 +0300 Subject: [PATCH] refactor: Admin --- Endpoint/Common/Model/Admin.cs | 10 ---------- Endpoint/Common/Settings/Admin.cs | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) delete mode 100644 Endpoint/Common/Model/Admin.cs create mode 100644 Endpoint/Common/Settings/Admin.cs diff --git a/Endpoint/Common/Model/Admin.cs b/Endpoint/Common/Model/Admin.cs deleted file mode 100644 index 59e4b60..0000000 --- a/Endpoint/Common/Model/Admin.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Mirea.Api.Endpoint.Common.Model; - -public class Admin -{ - public const string PathToSave = "admin.json"; - public required string Username { get; set; } - public required string Email { get; set; } - public required string PasswordHash { get; set; } - public required string Salt { get; set; } -} \ No newline at end of file diff --git a/Endpoint/Common/Settings/Admin.cs b/Endpoint/Common/Settings/Admin.cs new file mode 100644 index 0000000..0e41c36 --- /dev/null +++ b/Endpoint/Common/Settings/Admin.cs @@ -0,0 +1,25 @@ +using Mirea.Api.Endpoint.Common.Services; +using System.IO; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Mirea.Api.Endpoint.Common.Settings; + +public class Admin : ISaveSettings +{ + [JsonIgnore] private const string FileName = "admin.json"; + + [JsonIgnore] + public static string FilePath => PathBuilder.Combine(FileName); + + public required string Username { get; set; } + public required string Email { get; set; } + public required string PasswordHash { get; set; } + public required string Salt { get; set; } + + + public void SaveSetting() + { + File.WriteAllText(FilePath, JsonSerializer.Serialize(this)); + } +} \ No newline at end of file