feat: pk;config
This commit is contained in:
23
PluralKit.Core/Database/Repository/ModelRepository.Config.cs
Normal file
23
PluralKit.Core/Database/Repository/ModelRepository.Config.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public partial class ModelRepository
|
||||
{
|
||||
public Task<SystemConfig> GetSystemConfig(SystemId system)
|
||||
=> _db.QueryFirst<SystemConfig>(new Query("config").Where("system", system));
|
||||
|
||||
public async Task<SystemConfig> UpdateSystemConfig(SystemId system, SystemConfigPatch patch)
|
||||
{
|
||||
var query = patch.Apply(new Query("config").Where("system", system));
|
||||
var config = await _db.QueryFirst<SystemConfig>(query, "returning *");
|
||||
|
||||
_ = _dispatch.Dispatch(system, new UpdateDispatchData
|
||||
{
|
||||
Event = DispatchEvent.UPDATE_SETTINGS,
|
||||
EventData = patch.ToJson()
|
||||
});
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
#nullable enable
|
||||
using Dapper;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
@@ -78,6 +80,8 @@ public partial class ModelRepository
|
||||
var system = await _db.QueryFirst<PKSystem>(conn, query, "returning *");
|
||||
_logger.Information("Created {SystemId}", system.Id);
|
||||
|
||||
await _db.Execute(conn => conn.QueryAsync("insert into config (system) value (@system)", new { system = system.Id }));
|
||||
|
||||
// no dispatch call here - system was just created, we don't have a webhook URL
|
||||
return system;
|
||||
}
|
||||
|
Reference in New Issue
Block a user