init backend
This commit is contained in:
18
dotnet/AipsCore/Domain/Models/User/User.cs
Normal file
18
dotnet/AipsCore/Domain/Models/User/User.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.User;
|
||||
|
||||
public class User
|
||||
{
|
||||
public UserId Id { get; private set; }
|
||||
public Email Email { get; private set; }
|
||||
public Username Username { get; private set; }
|
||||
|
||||
public User(UserId id, Email email, Username username)
|
||||
{
|
||||
Id = id;
|
||||
Email = email;
|
||||
Username = username;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using AipsCore.Domain.Common.Validation.Rules;
|
||||
using AipsCore.Utility.Text;
|
||||
|
||||
namespace AipsCore.Domain.Models.User.Validation;
|
||||
|
||||
public class UsernameCharsetRule : CharsetRule
|
||||
{
|
||||
public UsernameCharsetRule(string stringValue)
|
||||
: base(stringValue, GetUsernameCharset())
|
||||
{
|
||||
}
|
||||
|
||||
private static char[] GetUsernameCharset()
|
||||
{
|
||||
var alphanumericCharset = Charset.GetAlphanumericCharset();
|
||||
|
||||
char[] usernameCharset = [..alphanumericCharset, '_'];
|
||||
|
||||
return usernameCharset;
|
||||
}
|
||||
|
||||
protected override string ErrorCode => "username_charset";
|
||||
|
||||
protected override string ErrorMessage =>
|
||||
"Username contains invalid characters, only alphanumeric characters and '_' are allowed";
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.User.ValueObjects;
|
||||
|
||||
public record UserId(string IdValue) : DomainId(IdValue);
|
||||
33
dotnet/AipsCore/Domain/Models/User/ValueObjects/Username.cs
Normal file
33
dotnet/AipsCore/Domain/Models/User/ValueObjects/Username.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Abstract.Rule;
|
||||
using AipsCore.Domain.Abstract.ValueObject;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Common.Validation.Rules;
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
using AipsCore.Domain.Models.User.Validation;
|
||||
|
||||
namespace AipsCore.Domain.Models.User.ValueObjects;
|
||||
|
||||
public record Username : AbstractValueObject
|
||||
{
|
||||
public string UsernameValue { get; init; }
|
||||
|
||||
public Username(string UsernameValue)
|
||||
{
|
||||
this.UsernameValue = UsernameValue;
|
||||
Validate();
|
||||
}
|
||||
|
||||
private const int MinimumLength = 8;
|
||||
private const int MaximumLength = 20;
|
||||
|
||||
protected override ICollection<IRule> GetValidationRules()
|
||||
{
|
||||
return
|
||||
[
|
||||
new MinLengthRule(UsernameValue, MinimumLength),
|
||||
new MaxLengthRule(UsernameValue, MaximumLength),
|
||||
new UsernameCharsetRule(UsernameValue)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using AipsCore.Domain.Common.Validation.Rules;
|
||||
using AipsCore.Utility.Text;
|
||||
|
||||
namespace AipsCore.Domain.Models.Whiteboard.Validation;
|
||||
|
||||
public class WhitebordCodeCharsetRule : CharsetRule
|
||||
{
|
||||
public WhitebordCodeCharsetRule(string stringValue)
|
||||
: base(stringValue, GetWhiteboardCodeCharset())
|
||||
{
|
||||
}
|
||||
|
||||
private static char[] GetWhiteboardCodeCharset()
|
||||
{
|
||||
return Charset.GetNumericCharset();
|
||||
}
|
||||
|
||||
protected override string ErrorCode => "whiteboard_code_charset";
|
||||
protected override string ErrorMessage => "Whiteboard code must contain only numbers";
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Abstract.Rule;
|
||||
using AipsCore.Domain.Abstract.ValueObject;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Common.Validation.Rules;
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.Validation;
|
||||
|
||||
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
public record WhiteboardCode : AbstractValueObject
|
||||
{
|
||||
public string CodeValue { get; init; }
|
||||
|
||||
public WhiteboardCode(string CodeValue)
|
||||
{
|
||||
this.CodeValue = CodeValue;
|
||||
Validate();
|
||||
}
|
||||
|
||||
private const int CodeLength = 8;
|
||||
|
||||
protected override ICollection<IRule> GetValidationRules()
|
||||
{
|
||||
return
|
||||
[
|
||||
new ExactLength(CodeValue, CodeLength),
|
||||
new WhitebordCodeCharsetRule(CodeValue)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
public record WhiteboardId(string IdValue) : DomainId(IdValue);
|
||||
18
dotnet/AipsCore/Domain/Models/Whiteboard/Whiteboard.cs
Normal file
18
dotnet/AipsCore/Domain/Models/Whiteboard/Whiteboard.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Whiteboard;
|
||||
|
||||
public class Whiteboard
|
||||
{
|
||||
public WhiteboardId Id { get; private set; }
|
||||
public UserId WhiteboardOwnerId { get; private set; }
|
||||
public WhiteboardCode Code { get; private set; }
|
||||
|
||||
public Whiteboard(WhiteboardId id, User.User whiteboardOwner, WhiteboardCode code)
|
||||
{
|
||||
Id = id;
|
||||
WhiteboardOwnerId = whiteboardOwner.Id;
|
||||
Code = code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user