From 988f68191bbd93ce225205ae2a0ebcdf9df45655 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Tue, 5 Sep 2023 01:01:24 +1000 Subject: Tag names and aliases are now verified to be unique --- Exception.cs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'Exception.cs') diff --git a/Exception.cs b/Exception.cs index 2005b1a..1e070eb 100644 --- a/Exception.cs +++ b/Exception.cs @@ -10,14 +10,44 @@ public class HBException : Exception { } public class ObjectNotFoundException : HBException { - public Guid Guid { get; set; } + public Guid Guid { get; private init; } public ObjectNotFoundException(Guid guid) : base($"Object not found: {guid}") {} } +public class TagException : HBException { + public TagDefinition? TagDefinition { get; private init; } + + public TagException(string message) : base(message) {} + public TagException(string message, TagDefinition tagDefinition) + : base(message) => + TagDefinition = tagDefinition; +} + +public class TagDuplicateException : TagException { + public bool NameExists { get; private init; } + public bool AliasExists { get; private init; } + + public TagDuplicateException(bool nameExists, bool aliasExists) + : base(GenerateMessage(nameExists, aliasExists)) { + + NameExists = nameExists; + AliasExists = aliasExists; + } + + private static string GenerateMessage(bool nameExists, bool aliasExists) { + if(nameExists && aliasExists) + return $"Both tag name and alias already exist!"; + else if(nameExists) + return $"Tag name already exists!"; + else + return $"Tag alias already exists"; + } +} + public class MediaException : HBException { - public Media? Media { get; set; } + public Media? Media { get; private init; } public MediaException(string message) : base(message) {} public MediaException(string message, Media media) : base(message) => -- cgit v1.3