summary refs log tree commit diff
path: root/extra/admin-api/Models
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-06-05 22:42:33 +0200
committerRory& <root@rory.gay>2026-06-05 22:42:33 +0200
commitd109d871d75d7ee707bb33342d5fed6865124166 (patch)
tree8685f6caa2dde878528eaa67ede8da803f734eb1 /extra/admin-api/Models
parentReturn url on webhook create (diff)
downloadserver-ts-d109d871d75d7ee707bb33342d5fed6865124166.tar.xz
Unit tests for webhooks
Diffstat (limited to 'extra/admin-api/Models')
-rw-r--r--extra/admin-api/Models/Spacebar.Models.Api/CreateWebhookRequest.cs11
-rw-r--r--extra/admin-api/Models/Spacebar.Models.Api/SpacebarApiError.cs5
-rw-r--r--extra/admin-api/Models/Spacebar.Models.Generic/Webhook.cs48
3 files changed, 63 insertions, 1 deletions
diff --git a/extra/admin-api/Models/Spacebar.Models.Api/CreateWebhookRequest.cs b/extra/admin-api/Models/Spacebar.Models.Api/CreateWebhookRequest.cs
new file mode 100644

index 00000000..19361b9f --- /dev/null +++ b/extra/admin-api/Models/Spacebar.Models.Api/CreateWebhookRequest.cs
@@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace Spacebar.Models.Api; + +public class CreateWebhookRequest { + [JsonPropertyName("name")] + public required string Name { get; set; } + + [JsonPropertyName("avatar")] + public string? AvatarData { get; set; } +} \ No newline at end of file diff --git a/extra/admin-api/Models/Spacebar.Models.Api/SpacebarApiError.cs b/extra/admin-api/Models/Spacebar.Models.Api/SpacebarApiError.cs
index 27ef7d14..bfbda6f5 100644 --- a/extra/admin-api/Models/Spacebar.Models.Api/SpacebarApiError.cs +++ b/extra/admin-api/Models/Spacebar.Models.Api/SpacebarApiError.cs
@@ -14,6 +14,8 @@ public class SpacebarApiException : Exception { public JsonObject? Errors { get; set; } public JsonObject?[]? AjvErrors { get; set; } + + public JsonObject? OriginalErrorData { get; init; } public class FieldErrorList { // public @@ -32,6 +34,7 @@ public class SpacebarApiException : Exception { } var ex = new SpacebarApiException(msg) { + OriginalErrorData = resp, Code = resp["code"]!.GetValue<int>(), ErrorMessage = resp["message"]!.GetValue<string>(), Request = resp["request"]?.GetValue<string>(), @@ -42,7 +45,7 @@ public class SpacebarApiException : Exception { return ex; } - public JsonObject AsJsonObject() => new() { + public JsonObject AsJsonObject() => OriginalErrorData?.DeepClone().AsObject() ?? new() { { "message", Message }, { "code", Code }, { "request", Request }, diff --git a/extra/admin-api/Models/Spacebar.Models.Generic/Webhook.cs b/extra/admin-api/Models/Spacebar.Models.Generic/Webhook.cs new file mode 100644
index 00000000..ba48649f --- /dev/null +++ b/extra/admin-api/Models/Spacebar.Models.Generic/Webhook.cs
@@ -0,0 +1,48 @@ +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; + +namespace Spacebar.Models.Generic; + +public class Webhook { + [JsonPropertyName("id"), JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] + public required long Id { get; set; } + + [JsonPropertyName("type")] + public WebhookType WebhookType { get; set; } + + [JsonPropertyName("guild_id"), JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] + public long? GuildId { get; set; } + + [JsonPropertyName("channel_id"), JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] + public long? ChannelId { get; set; } + + [JsonPropertyName("user")] + public PartialUser? User { get; set; } + + [JsonPropertyName("name")] + public string? Name { get; set; } + + [JsonPropertyName("avatar")] + public string? AvatarData { get; set; } + + [JsonPropertyName("token")] + public string? Token { get; set; } + + [JsonPropertyName("application_id"), JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] + public long? ApplicationId { get; set; } + + [JsonPropertyName("source_guild")] + public JsonObject? SourceGuild { get; set; } // TODO type + + [JsonPropertyName("source_channel")] + public JsonObject? SourceChannel { get; set; } // TODO type + + [JsonPropertyName("url")] + public string? Url { get; set; } +} + +public enum WebhookType : byte { + Incomming = 1, + ChannelFollower = 2, + Application = 3 +} \ No newline at end of file