diff options
| author | Jake Mannens <jake@asger.xyz> | 2026-06-15 10:34:43 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2026-06-15 10:34:43 +1000 |
| commit | 2d621a7f0b5fea6388d6ad104a14aa06149ff7a7 (patch) | |
| tree | 1a4f51d1cce99b84ceefa6f26d12ee61e6f48a58 | |
| parent | f884eb32b2aebb8aef73d4eff6231f244020d68c (diff) | |
| -rw-r--r-- | ApiModels.cs | 17 | ||||
| -rw-r--r-- | ApiModels.csproj | 4 | ||||
| -rw-r--r-- | Exception.cs | 30 | ||||
| -rw-r--r-- | Statistics.cs | 6 |
4 files changed, 44 insertions, 13 deletions
diff --git a/ApiModels.cs b/ApiModels.cs index 534f46b..6ac744e 100644 --- a/ApiModels.cs +++ b/ApiModels.cs @@ -7,6 +7,11 @@ public enum PathType { Unix } +public enum TagSource { + Internal = 0, + UserTag = 1 +} + public record Media { public Guid MediaId { get; init; } public string? ShortDescription { get; init; } @@ -33,11 +38,13 @@ public record UploadedFile { } public record TagDefinition { - public Guid TagDefinitionId { get; init; } - public string? Namespace { get; init; } - public string Name { get; init; } - public string? Alias { get; init; } - public Guid[] ImplicitTags { get; init; } + public Guid TagDefinitionId { get; init; } + [JsonConverter(typeof(JsonStringEnumConverter))] + public TagSource Source { get; init; } + public string? Namespace { get; init; } + public string Name { get; init; } + public string? Alias { get; init; } + public Guid[] ImplicitTags { get; init; } } public record User { diff --git a/ApiModels.csproj b/ApiModels.csproj index 1623f92..6a1f73d 100644 --- a/ApiModels.csproj +++ b/ApiModels.csproj @@ -7,9 +7,9 @@ <AssemblyTitle>HyperBooru.ApiModels</AssemblyTitle> <RootNamespace>HyperBooru.ApiModels</RootNamespace> <AssemblyName>HyperBooru.ApiModels</AssemblyName> - <AssemblyVersion>0.17.0.0</AssemblyVersion> + <AssemblyVersion>0.18.0.0</AssemblyVersion> <FileVersion>$(AssemblyVersion)</FileVersion> - <Version>0.17-alpha</Version> + <Version>0.18-alpha</Version> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)' == 'Release'"> diff --git a/Exception.cs b/Exception.cs index 5299522..3f7f7ca 100644 --- a/Exception.cs +++ b/Exception.cs @@ -3,9 +3,11 @@ namespace HyperBooru.ApiModels; [JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")] +[JsonDerivedType(typeof(ArgumentException), typeDiscriminator: "argumentException")] [JsonDerivedType(typeof(MediaCreateException), typeDiscriminator: "mediaCreateException")] [JsonDerivedType(typeof(MediaException), typeDiscriminator: "mediaException")] [JsonDerivedType(typeof(ObjectNotFoundException), typeDiscriminator: "objectNotFoundException")] +[JsonDerivedType(typeof(ServerException), typeDiscriminator: "serverException")] [JsonDerivedType(typeof(TagDuplicateException), typeDiscriminator: "tagDuplicateException")] [JsonDerivedType(typeof(TagException), typeDiscriminator: "tagException")] [JsonDerivedType(typeof(ThumbnailException), typeDiscriminator: "thumbnailException")] @@ -19,16 +21,32 @@ public class HBException : Exception { : base(message, inner) {} } +[ExceptionStatusCode(500)] +public class ServerException : HBException { + [JsonConstructor] + public ServerException() + : base("An unknown server error occurred") {} +} + +[ExceptionStatusCode(400)] +public class ArgumentException : HBException { + [JsonConstructor] + public ArgumentException(string message) : base(message) {} +} + [ExceptionStatusCode(404)] public class ObjectNotFoundException : HBException { - public Guid Guid { get; } + public Guid[] MissingObjects { get; } [JsonConstructor] - public ObjectNotFoundException(Guid guid) - : base($"Object not found: {guid}") { + public ObjectNotFoundException(IEnumerable<Guid> missingObjects) + : base(GetMessage(missingObjects)) { - Guid = guid; + MissingObjects = missingObjects.Distinct().ToArray(); } + + private static string GetMessage(IEnumerable<Guid> missingObjects) => + $"Unable to find object(s): {string.Join(", ", missingObjects.Order().Distinct())}"; } public class TagException : HBException { @@ -48,13 +66,13 @@ public class TagDuplicateException : TagException { [JsonConstructor] public TagDuplicateException(bool nameExists, bool aliasExists) - : base(GenerateMessage(nameExists, aliasExists)) { + : base(GetMessage(nameExists, aliasExists)) { NameExists = nameExists; AliasExists = aliasExists; } - private static string GenerateMessage(bool nameExists, bool aliasExists) { + private static string GetMessage(bool nameExists, bool aliasExists) { if(nameExists && aliasExists) return $"Both tag name and alias already exist!"; else if(nameExists) diff --git a/Statistics.cs b/Statistics.cs new file mode 100644 index 0000000..f59a2f6 --- /dev/null +++ b/Statistics.cs @@ -0,0 +1,6 @@ +namespace HyperBooru.ApiModels; + +public record IngestStatistics { + public int TotalMediaCount { get; set; } + public int UntaggedMediaCount { get; set; } +} |
