structure app by rest api standards

add getusers
tidy up BusinessException
This commit is contained in:
Alex Bezdieniezhnykh
2024-11-14 22:45:36 +02:00
parent ace57eaf27
commit 4bc76bbbac
12 changed files with 182 additions and 37 deletions
+39 -10
View File
@@ -1,20 +1,49 @@
namespace Azaion.Common;
using System.ComponentModel;
using Azaion.Common.Extensions;
public class BusinessException(ExceptionEnum exEnum, string message) : Exception(message)
namespace Azaion.Common;
public class BusinessException(ExceptionEnum exEnum) : Exception(GetMessage(exEnum))
{
private static readonly Dictionary<ExceptionEnum, string> ExceptionDescriptions;
static BusinessException()
{
ExceptionDescriptions = EnumExtensions.GetDescriptions<ExceptionEnum>();
}
private ExceptionEnum ExceptionEnum { get; set; } = exEnum;
public static string GetMessage(ExceptionEnum exEnum) => ExceptionDescriptions.GetValueOrDefault(exEnum) ?? exEnum.ToString();
}
public enum ExceptionEnum
{
NoUserFound = 10,
NoUser = 15,
UserExists = 20,
PasswordIncorrect = 30,
UserLengthIncorrect = 33,
WrongEmail = 35,
PasswordLengthIncorrect = 37,
[Description("No such email found.")]
NoEmailFound = 10,
[Description("Email already exists.")]
EmailExists = 20,
[Description("Passwords do not match.")]
WrongPassword = 30,
[Description("Password should be at least 8 characters.")]
PasswordLengthIncorrect = 32,
EmailLengthIncorrect = 35,
WrongEmail = 37,
[Description("Hardware mismatch! You are not authorized to access this resource from this hardware.")]
HardwareIdMismatch = 40,
[Description("Hardware Id should be at least 8 characters.")]
HardwareIdLength = 45,
[Description("Wrong resource type.")]
WrongResourceType = 50,
NoFile = 60
[Description("No file provided.")]
NoFileProvided = 60,
}