Added roles (may or may not be used)

This commit is contained in:
Veljko Tosic
2026-02-12 20:25:51 +01:00
parent 86f66727f3
commit 5ecf8435f4
5 changed files with 71 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
using AipsCore.Domain.Common.Validation;
using AipsCore.Domain.Models.User.Validation;
namespace AipsCore.Domain.Models.User.External;
public record UserRole
{
public string Name { get; init; }
private UserRole(string Name)
{
this.Name = Name;
}
public static UserRole User => new("User");
public static UserRole Admin => new("Admin");
public static IEnumerable<UserRole> All() => [User, Admin];
public static UserRole FromString(string name)
{
var role = All().FirstOrDefault(r => r.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
return role ?? throw new ValidationException(UserErrors.RoleDoesNotExist(name));
}
}