Expanded on existing whiteboard

This commit is contained in:
Veljko Tosic
2026-02-09 22:24:33 +01:00
parent 73b222b763
commit db122da753
12 changed files with 237 additions and 20 deletions

View File

@@ -4,10 +4,10 @@ namespace AipsCore.Domain.Common.Validation.Rules;
public class DateInFutureRule : AbstractRule
{
private readonly DateTime _date;
private readonly DateTime? _date;
private readonly DateTime _now;
public DateInFutureRule(DateTime date)
public DateInFutureRule(DateTime? date)
{
_date = date;
_now = DateTime.Now;
@@ -17,6 +17,11 @@ public class DateInFutureRule : AbstractRule
protected override string ErrorMessage => "Date must be in the future";
public override bool Validate()
{
return _date > _now;
if (_date is not null)
{
return _date > _now;
}
return true;
}
}

View File

@@ -4,10 +4,10 @@ namespace AipsCore.Domain.Common.Validation.Rules;
public class DateInPastRule : AbstractRule
{
private readonly DateTime _date;
private readonly DateTime? _date;
private readonly DateTime _now;
public DateInPastRule(DateTime date)
public DateInPastRule(DateTime? date)
{
_date = date;
_now = DateTime.Now;
@@ -17,6 +17,11 @@ public class DateInPastRule : AbstractRule
protected override string ErrorMessage => "Date must be in the past";
public override bool Validate()
{
return _date < _now;
if (_date is not null)
{
return _date < _now;
}
return true;
}
}

View File

@@ -0,0 +1,8 @@
namespace AipsCore.Domain.Models.Whiteboard.Enums;
public enum WhiteboardJoinPolicy
{
FreeToJoin,
RequestToJoin,
Private
}

View File

@@ -0,0 +1,8 @@
namespace AipsCore.Domain.Models.Whiteboard.Enums;
public enum WhiteboardState
{
Active,
Inactive,
Deleted
}

View File

@@ -0,0 +1,23 @@
using AipsCore.Domain.Abstract.Rule;
using AipsCore.Domain.Abstract.ValueObject;
using AipsCore.Domain.Common.Validation.Rules;
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
public record WhiteboardCreatedAt : AbstractValueObject
{
public DateTime CreatedAtValue { get; init; }
public WhiteboardCreatedAt(DateTime CreatedAtValue)
{
this.CreatedAtValue = CreatedAtValue;
Validate();
}
protected override ICollection<IRule> GetValidationRules()
{
return [
new DateInPastRule(CreatedAtValue)
];
}
}

View File

@@ -0,0 +1,23 @@
using AipsCore.Domain.Abstract.Rule;
using AipsCore.Domain.Abstract.ValueObject;
using AipsCore.Domain.Common.Validation.Rules;
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
public record WhiteboardDeletedAt : AbstractValueObject
{
public DateTime? DeletedAtValue { get; init; }
public WhiteboardDeletedAt(DateTime? DeletedAtValue)
{
this.DeletedAtValue = DeletedAtValue;
Validate();
}
protected override ICollection<IRule> GetValidationRules()
{
return [
new DateInPastRule(DeletedAtValue)
];
}
}

View File

@@ -0,0 +1,25 @@
using AipsCore.Domain.Abstract.Rule;
using AipsCore.Domain.Abstract.ValueObject;
using AipsCore.Domain.Common.Validation.Rules;
namespace AipsCore.Domain.Models.Whiteboard.ValueObjects;
public record WhiteboardMaxParticipants : AbstractValueObject
{
private const int MinMaxParticipants = 1;
private const int MaxMaxParticipants = 100;
public int MaxParticipantsValue { get; init; }
public WhiteboardMaxParticipants(int MaxParticipantsValue)
{
this.MaxParticipantsValue = MaxParticipantsValue;
Validate();
}
protected override ICollection<IRule> GetValidationRules()
{
return [
new MinValueRule<int>(MaxParticipantsValue, MinMaxParticipants),
new MaxValueRule<int>(MaxParticipantsValue, MaxMaxParticipants)
];
}
}

View File

@@ -1,4 +1,5 @@
using AipsCore.Domain.Models.User.ValueObjects;
using AipsCore.Domain.Models.Whiteboard.Enums;
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
namespace AipsCore.Domain.Models.Whiteboard;
@@ -9,40 +10,114 @@ public class Whiteboard
public UserId WhiteboardOwnerId { get; private set; }
public WhiteboardCode Code { get; private set; }
public WhiteboardTitle Title { get; private set; }
public WhiteboardCreatedAt CreatedAt { get; private set; }
public WhiteboardDeletedAt DeletedAt { get; private set; }
public WhiteboardMaxParticipants MaxParticipants { get; private set; }
public WhiteboardJoinPolicy JoinPolicy { get; private set; }
public WhiteboardState State { get; private set; }
public Whiteboard(WhiteboardId id, User.User whiteboardOwner, WhiteboardCode code, WhiteboardTitle title)
public Whiteboard(
WhiteboardId id,
User.User whiteboardOwner,
WhiteboardCode code,
WhiteboardTitle title,
WhiteboardCreatedAt createdAt,
WhiteboardDeletedAt deletedAt,
WhiteboardMaxParticipants maxParticipants,
WhiteboardJoinPolicy joinPolicy,
WhiteboardState state)
{
Id = id;
WhiteboardOwnerId = whiteboardOwner.Id;
Code = code;
Title = title;
CreatedAt = createdAt;
DeletedAt = deletedAt;
MaxParticipants = maxParticipants;
JoinPolicy = joinPolicy;
State = state;
}
public Whiteboard(WhiteboardId id, UserId whiteboardOwnerId, WhiteboardCode code, WhiteboardTitle title)
public Whiteboard(
WhiteboardId id,
UserId whiteboardOwnerId,
WhiteboardCode code,
WhiteboardTitle title,
WhiteboardCreatedAt createdAt,
WhiteboardDeletedAt deletedAt,
WhiteboardMaxParticipants maxParticipants,
WhiteboardJoinPolicy joinPolicy,
WhiteboardState state)
{
Id = id;
WhiteboardOwnerId = whiteboardOwnerId;
Code = code;
Title = title;
Title = title;
CreatedAt = createdAt;
DeletedAt = deletedAt;
MaxParticipants = maxParticipants;
JoinPolicy = joinPolicy;
State = state;
}
public static Whiteboard Create(string id, string ownerId, string code, string title)
public static Whiteboard Create(
string id,
string ownerId,
string code,
string title,
DateTime createdAt,
DateTime? deletedAt,
int maxParticipants,
WhiteboardJoinPolicy joinPolicy,
WhiteboardState state)
{
var whiteboardId = new WhiteboardId(id);
var whiteboardOwnerId = new UserId(ownerId);
var whiteboardCode = new WhiteboardCode(code);
var whiteboardTitle = new WhiteboardTitle(title);
var whiteboardCreatedAt = new WhiteboardCreatedAt(createdAt);
var whiteboardDeletedAt = new WhiteboardDeletedAt(deletedAt);
var whiteboardMaxParticipants = new WhiteboardMaxParticipants(maxParticipants);
return new Whiteboard(whiteboardId, whiteboardOwnerId, whiteboardCode, whiteboardTitle);
return new Whiteboard(
whiteboardId,
whiteboardOwnerId,
whiteboardCode,
whiteboardTitle,
whiteboardCreatedAt,
whiteboardDeletedAt,
whiteboardMaxParticipants,
joinPolicy,
state);
}
public static Whiteboard Create(string ownerId, string code, string title)
public static Whiteboard Create(
string ownerId,
string code,
string title,
DateTime createdAt,
DateTime? deletedAt,
int maxParticipants,
WhiteboardJoinPolicy joinPolicy,
WhiteboardState state)
{
var whiteboardId = WhiteboardId.Any();
var whiteboardOwnerId = new UserId(ownerId);
var whiteboardCode = new WhiteboardCode(code);
var whiteboardTitle = new WhiteboardTitle(title);
var whiteboardCreatedAt = new WhiteboardCreatedAt(createdAt);
var whiteboardDeletedAt = new WhiteboardDeletedAt(deletedAt);
var whiteboardMaxParticipants = new WhiteboardMaxParticipants(maxParticipants);
return new Whiteboard(whiteboardId, whiteboardOwnerId, whiteboardCode, whiteboardTitle);
return new Whiteboard(
whiteboardId,
whiteboardOwnerId,
whiteboardCode,
whiteboardTitle,
whiteboardCreatedAt,
whiteboardDeletedAt,
whiteboardMaxParticipants,
joinPolicy,
state);
}
}