PluralKit/PluralKit.Core/Models/Patch/GroupPatch.cs
spiral 4b944e2b20
feat: refactor external input handling code
- refactor import/export code
- make import/export use the same JSON parsing as API
- make Patch.AssertIsValid actually useful
2021-08-25 21:43:31 -04:00

45 lines
1.8 KiB
C#

#nullable enable
using System.Text.RegularExpressions;
namespace PluralKit.Core
{
public class GroupPatch: PatchObject
{
public Partial<string> Name { get; set; }
public Partial<string> Hid { get; set; }
public Partial<string?> DisplayName { get; set; }
public Partial<string?> Description { get; set; }
public Partial<string?> Icon { get; set; }
public Partial<string?> BannerImage { get; set; }
public Partial<string?> Color { get; set; }
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
public Partial<PrivacyLevel> IconPrivacy { get; set; }
public Partial<PrivacyLevel> ListPrivacy { get; set; }
public Partial<PrivacyLevel> Visibility { get; set; }
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
.With("name", Name)
.With("hid", Hid)
.With("display_name", DisplayName)
.With("description", Description)
.With("icon", Icon)
.With("banner_image", BannerImage)
.With("color", Color)
.With("description_privacy", DescriptionPrivacy)
.With("icon_privacy", IconPrivacy)
.With("list_privacy", ListPrivacy)
.With("visibility", Visibility);
public new void AssertIsValid()
{
if (Icon.Value != null && !MiscUtils.TryMatchUri(Icon.Value, out var avatarUri))
throw new ValidationError("icon");
if (BannerImage.Value != null && !MiscUtils.TryMatchUri(BannerImage.Value, out var bannerImage))
throw new ValidationError("banner");
if (Color.Value != null && (!Regex.IsMatch(Color.Value, "^[0-9a-fA-F]{6}$")))
throw new ValidationError("color");
}
}
}