2024-10-19 01:50:46 +00:00
|
|
|
using HermesSocketLibrary.db;
|
|
|
|
using HermesSocketServer.Models;
|
2024-12-31 18:31:21 +00:00
|
|
|
using HermesSocketServer.Store.Internal;
|
2024-10-19 01:50:46 +00:00
|
|
|
|
|
|
|
namespace HermesSocketServer.Store
|
|
|
|
{
|
2024-12-31 18:31:21 +00:00
|
|
|
public class UserStore : AutoSavedStore<string, User>
|
2024-10-19 01:50:46 +00:00
|
|
|
{
|
|
|
|
private readonly Database _database;
|
|
|
|
private readonly Serilog.ILogger _logger;
|
|
|
|
|
|
|
|
|
2024-12-31 18:31:21 +00:00
|
|
|
public UserStore([FromKeyedServices("User")] DatabaseTable table, Database database, Serilog.ILogger logger)
|
|
|
|
: base(table, database, logger)
|
2024-10-19 01:50:46 +00:00
|
|
|
{
|
|
|
|
_database = database;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task Load()
|
|
|
|
{
|
|
|
|
string sql = "SELECT id, name, email, role, \"ttsDefaultVoice\" FROM \"User\";";
|
|
|
|
await _database.Execute(sql, new Dictionary<string, object>(), (reader) =>
|
|
|
|
{
|
|
|
|
string id = reader.GetString(0);
|
|
|
|
_store.Add(id, new User()
|
|
|
|
{
|
|
|
|
Id = id,
|
|
|
|
Name = reader.GetString(1),
|
|
|
|
Email = reader.GetString(2),
|
|
|
|
Role = reader.GetString(3),
|
|
|
|
DefaultVoice = reader.GetString(4),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
_logger.Information($"Loaded {_store.Count} users from database.");
|
|
|
|
}
|
|
|
|
|
2024-10-20 18:07:18 +00:00
|
|
|
protected override void OnInitialAdd(string key, User value)
|
2024-10-19 01:50:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-10-20 18:07:18 +00:00
|
|
|
protected override void OnInitialModify(string key, User value)
|
2024-10-19 01:50:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-10-20 18:07:18 +00:00
|
|
|
protected override void OnInitialRemove(string key)
|
2024-10-19 01:50:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|