Move system updates to the same patch system as members
This commit is contained in:
@@ -4,7 +4,7 @@ using NodaTime;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class MemberPatch: PatchObject<MemberId, PKMember>
|
||||
public class MemberPatch: PatchObject
|
||||
{
|
||||
public Partial<string> Name { get; set; }
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
|
31
PluralKit.Core/Models/Patch/ModelPatchExt.cs
Normal file
31
PluralKit.Core/Models/Patch/ModelPatchExt.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dapper;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public static class ModelPatchExt
|
||||
{
|
||||
public static Task<PKSystem> UpdateSystem(this IPKConnection conn, SystemId id, SystemPatch patch)
|
||||
{
|
||||
var (query, pms) = patch.Apply(new UpdateQueryBuilder("systems", "id = @id"))
|
||||
.WithConstant("id", id)
|
||||
.Build("returning *");
|
||||
return conn.QueryFirstAsync<PKSystem>(query, pms);
|
||||
}
|
||||
|
||||
public static Task DeleteSystem(this IPKConnection conn, SystemId id) =>
|
||||
conn.ExecuteAsync("delete from systems where id = @Id", new {Id = id});
|
||||
|
||||
public static Task<PKMember> UpdateMember(this IPKConnection conn, MemberId id, MemberPatch patch)
|
||||
{
|
||||
var (query, pms) = patch.Apply(new UpdateQueryBuilder("members", "id = @id"))
|
||||
.WithConstant("id", id)
|
||||
.Build("returning *");
|
||||
return conn.QueryFirstAsync<PKMember>(query, pms);
|
||||
}
|
||||
|
||||
public static Task DeleteMember(this IPKConnection conn, MemberId id) =>
|
||||
conn.ExecuteAsync("delete from members where id = @Id", new {Id = id});
|
||||
}
|
||||
}
|
@@ -1,8 +1,6 @@
|
||||
using PluralKit.Core;
|
||||
|
||||
namespace PluralKit.Core
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public abstract class PatchObject<TKey, TObj>
|
||||
public abstract class PatchObject
|
||||
{
|
||||
public abstract UpdateQueryBuilder Apply(UpdateQueryBuilder b);
|
||||
}
|
||||
|
31
PluralKit.Core/Models/Patch/SystemPatch.cs
Normal file
31
PluralKit.Core/Models/Patch/SystemPatch.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
#nullable enable
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class SystemPatch: PatchObject
|
||||
{
|
||||
public Partial<string?> Name { get; set; }
|
||||
public Partial<string?> Description { get; set; }
|
||||
public Partial<string?> Tag { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
public Partial<string?> Token { get; set; }
|
||||
public Partial<string> UiTz { get; set; }
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> MemberListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> FrontPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> FrontHistoryPrivacy { get; set; }
|
||||
public Partial<bool> PingsEnabled { get; set; }
|
||||
|
||||
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
|
||||
.With("name", Name)
|
||||
.With("description", Description)
|
||||
.With("tag", Tag)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
.With("token", Token)
|
||||
.With("ui_tz", UiTz)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("member_list_privacy", MemberListPrivacy)
|
||||
.With("front_privacy", FrontPrivacy)
|
||||
.With("front_history_privacy", FrontHistoryPrivacy)
|
||||
.With("pings_enabled", PingsEnabled);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user