Added stores for groups, group chatters and group permissions. Fixed some logging text.
This commit is contained in:
64
Store/GroupPermissionStore.cs
Normal file
64
Store/GroupPermissionStore.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using HermesSocketServer.Store.Internal;
|
||||
|
||||
namespace HermesSocketServer.Store
|
||||
{
|
||||
public class GroupPermissionStore : AutoSavedStore<string, GroupPermission>
|
||||
{
|
||||
private readonly string _userId;
|
||||
private readonly Database _database;
|
||||
private readonly Serilog.ILogger _logger;
|
||||
|
||||
|
||||
public GroupPermissionStore(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<string, object>() { { "user", _userId } };
|
||||
string sql = $"SELECT id, \"groupId\", path, allow FROM \"GroupPermission\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, data, async (reader) =>
|
||||
{
|
||||
var id = reader.GetGuid(0).ToString();
|
||||
_store.Add(id, new GroupPermission()
|
||||
{
|
||||
Id = id,
|
||||
UserId = _userId,
|
||||
GroupId = reader.GetGuid(1).ToString(),
|
||||
Path = reader.GetString(2),
|
||||
Allow = await reader.IsDBNullAsync(3) ? null : reader.GetBoolean(3),
|
||||
});
|
||||
});
|
||||
_logger.Information($"Loaded {_store.Count} group permissions from database.");
|
||||
}
|
||||
|
||||
protected override void OnInitialAdd(string key, GroupPermission value)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(key, nameof(key));
|
||||
ArgumentNullException.ThrowIfNull(value, nameof(value));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(value.UserId, nameof(value.UserId));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(value.GroupId, nameof(value.GroupId));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(value.Path, nameof(value.Path));
|
||||
}
|
||||
|
||||
protected override void OnInitialModify(string key, GroupPermission oldValue, GroupPermission newValue)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newValue, nameof(newValue));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(newValue.UserId, nameof(newValue.UserId));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(newValue.GroupId, nameof(newValue.GroupId));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(newValue.Path, nameof(newValue.Path));
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(oldValue.UserId, newValue.UserId, nameof(oldValue.UserId));
|
||||
ArgumentOutOfRangeException.ThrowIfNotEqual(oldValue.GroupId, newValue.GroupId, nameof(oldValue.GroupId));
|
||||
}
|
||||
|
||||
protected override void OnPostRemove(string key, GroupPermission value)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user