feat(webhooks): init, add service/models, add JSON to patch objects

This commit is contained in:
spiral
2021-11-02 06:08:17 -04:00
parent 08c5b78cc2
commit 71aec0d419
14 changed files with 551 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
-- schema version 20: insert date
-- add outgoing webhook to systems
alter table systems add column webhook_url text;
alter table systems add column webhook_token text;
update info set schema_version = 20;

View File

@@ -8,6 +8,12 @@ namespace PluralKit.Core
{
public partial class ModelRepository
{
public Task<PKGroup?> GetGroup(GroupId id)
{
var query = new Query("groups").Where("id", id);
return _db.QueryFirst<PKGroup?>(query);
}
public Task<PKGroup?> GetGroupByName(SystemId system, string name)
{
var query = new Query("groups").Where("system", system).WhereRaw("lower(name) = lower(?)", name.ToLower());

View File

@@ -100,6 +100,9 @@ namespace PluralKit.Core
return _db.QueryStream<PKSwitch>(query);
}
public Task<PKSwitch?> GetSwitch(SwitchId id)
=> _db.QueryFirst<PKSwitch?>(new Query("switches").Where("id", id));
public Task<PKSwitch> GetSwitchByUuid(Guid uuid)
{
var query = new Query("switches").Where("uuid", uuid);

View File

@@ -6,10 +6,12 @@ namespace PluralKit.Core
{
private readonly ILogger _logger;
private readonly IDatabase _db;
public ModelRepository(ILogger logger, IDatabase db)
private readonly DispatchService _dispatch;
public ModelRepository(ILogger logger, IDatabase db, DispatchService dispatch)
{
_logger = logger.ForContext<ModelRepository>();
_db = db;
_dispatch = dispatch;
}
}
}

View File

@@ -12,7 +12,7 @@ namespace PluralKit.Core
internal class DatabaseMigrator
{
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
private const int TargetSchemaVersion = 19;
private const int TargetSchemaVersion = 20;
private readonly ILogger _logger;
public DatabaseMigrator(ILogger logger)