using HermesSocketLibrary.db; using HermesSocketLibrary.Requests.Messages; using HermesSocketServer.Store.Internal; namespace HermesSocketServer.Store { public class RedemptionStore : AutoSavedStore { private readonly string _userId; private readonly Database _database; private readonly Serilog.ILogger _logger; public RedemptionStore(string userId, DatabaseTable table, Database database, Serilog.ILogger logger) : base(table, database, logger) { _userId = userId; _database = database; _logger = logger; } public override async Task Load() { var data = new Dictionary() { { "user", _userId } }; string sql = $"SELECT id, \"redemptionId\", \"order\", \"state\", \"actionName\" FROM \"Redemption\" WHERE \"userId\" = @user"; await _database.Execute(sql, data, (reader) => { var id = reader.GetGuid(0); _store.Add(id.ToString(), new Redemption() { Id = id.ToString(), UserId = _userId, RedemptionId = reader.GetString(1), Order = reader.GetInt32(2), State = reader.GetBoolean(3), ActionName = reader.GetString(4), }); }); _logger.Information($"Loaded {_store.Count} TTS chatter voices from database."); } protected override void OnInitialAdd(string key, Redemption value) { } protected override void OnInitialModify(string key, Redemption value) { } protected override void OnInitialRemove(string key) { } } }