Merge pull request #10 from StewKI/feature-whiteboard-expansion
Expanded on existing whiteboard
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
using System.Windows.Input;
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Domain.Models.Whiteboard.Enums;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
||||
|
||||
public record CreateWhiteboardCommand(string OwnerId, string Title) : ICommand<WhiteboardId>;
|
||||
public record CreateWhiteboardCommand(
|
||||
string OwnerId,
|
||||
string Title,
|
||||
DateTime CreatedAt,
|
||||
DateTime DeletedAt,
|
||||
int MaxParticipants,
|
||||
WhiteboardJoinPolicy JoinPolicy,
|
||||
WhiteboardState State)
|
||||
: ICommand<WhiteboardId>;
|
||||
@@ -20,7 +20,15 @@ public class CreateWhiteboardCommandHandler : ICommandHandler<CreateWhiteboardCo
|
||||
{
|
||||
var whiteboardCode = await WhiteboardCode.GenerateUniqueAsync(_whiteboardRepository);
|
||||
|
||||
var whiteboard = Domain.Models.Whiteboard.Whiteboard.Create(command.OwnerId, whiteboardCode.CodeValue, command.Title);
|
||||
var whiteboard = Domain.Models.Whiteboard.Whiteboard.Create(
|
||||
command.OwnerId,
|
||||
whiteboardCode.CodeValue,
|
||||
command.Title,
|
||||
command.CreatedAt,
|
||||
command.DeletedAt,
|
||||
command.MaxParticipants,
|
||||
command.JoinPolicy,
|
||||
command.State);
|
||||
|
||||
await _whiteboardRepository.Save(whiteboard, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AipsCore.Domain.Models.Whiteboard.Enums;
|
||||
|
||||
public enum WhiteboardJoinPolicy
|
||||
{
|
||||
FreeToJoin,
|
||||
RequestToJoin,
|
||||
Private
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AipsCore.Domain.Models.Whiteboard.Enums;
|
||||
|
||||
public enum WhiteboardState
|
||||
{
|
||||
Active,
|
||||
Inactive,
|
||||
Deleted
|
||||
}
|
||||
@@ -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)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AipsCore.Domain.Models.Whiteboard.Enums;
|
||||
|
||||
namespace AipsCore.Infrastructure.Persistence.Whiteboard;
|
||||
|
||||
@@ -8,7 +9,9 @@ public class Whiteboard
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public Guid WhiteboardOwnerId { get; set; }
|
||||
public Guid OwnerId { get; set; }
|
||||
|
||||
public User.User Owner { get; set; } = null!;
|
||||
|
||||
[Required]
|
||||
[MaxLength(8)]
|
||||
@@ -19,4 +22,14 @@ public class Whiteboard
|
||||
[MaxLength(32)]
|
||||
[MinLength(3)]
|
||||
public string Title { get; set; } = null!;
|
||||
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
public DateTime? DeletedAt { get; set; }
|
||||
|
||||
public int MaxParticipants { get; set; }
|
||||
|
||||
public WhiteboardJoinPolicy JoinPolicy { get; set; }
|
||||
|
||||
public WhiteboardState State { get; set; }
|
||||
}
|
||||
@@ -22,9 +22,14 @@ public class WhiteboardRepository : IWhiteboardRepository
|
||||
|
||||
return Domain.Models.Whiteboard.Whiteboard.Create(
|
||||
whiteboardEntity.Id.ToString(),
|
||||
whiteboardEntity.WhiteboardOwnerId.ToString(),
|
||||
whiteboardEntity.OwnerId.ToString(),
|
||||
whiteboardEntity.Code,
|
||||
whiteboardEntity.Title);
|
||||
whiteboardEntity.Title,
|
||||
whiteboardEntity.CreatedAt,
|
||||
whiteboardEntity.DeletedAt,
|
||||
whiteboardEntity.MaxParticipants,
|
||||
whiteboardEntity.JoinPolicy,
|
||||
whiteboardEntity.State);
|
||||
}
|
||||
|
||||
public async Task Save(Domain.Models.Whiteboard.Whiteboard whiteboard, CancellationToken cancellationToken = default)
|
||||
@@ -33,9 +38,14 @@ public class WhiteboardRepository : IWhiteboardRepository
|
||||
|
||||
if (whiteboardEntity is not null)
|
||||
{
|
||||
whiteboardEntity.WhiteboardOwnerId = new Guid(whiteboard.WhiteboardOwnerId.IdValue);
|
||||
whiteboardEntity.OwnerId = new Guid(whiteboard.WhiteboardOwnerId.IdValue);
|
||||
whiteboardEntity.Code = whiteboard.Code.CodeValue;
|
||||
whiteboardEntity.Title = whiteboard.Title.TitleValue;
|
||||
whiteboardEntity.CreatedAt = whiteboard.CreatedAt.CreatedAtValue;
|
||||
whiteboardEntity.DeletedAt = whiteboard.DeletedAt.DeletedAtValue;
|
||||
whiteboardEntity.MaxParticipants = whiteboard.MaxParticipants.MaxParticipantsValue;
|
||||
whiteboardEntity.JoinPolicy = whiteboard.JoinPolicy;
|
||||
whiteboardEntity.State = whiteboard.State;
|
||||
|
||||
_context.Whiteboards.Update(whiteboardEntity);
|
||||
}
|
||||
@@ -44,9 +54,14 @@ public class WhiteboardRepository : IWhiteboardRepository
|
||||
whiteboardEntity = new Whiteboard()
|
||||
{
|
||||
Id = new Guid(whiteboard.Id.IdValue),
|
||||
WhiteboardOwnerId = new Guid(whiteboard.WhiteboardOwnerId.IdValue),
|
||||
OwnerId = new Guid(whiteboard.WhiteboardOwnerId.IdValue),
|
||||
Code = whiteboard.Code.CodeValue,
|
||||
Title = whiteboard.Title.TitleValue,
|
||||
CreatedAt = whiteboard.CreatedAt.CreatedAtValue,
|
||||
DeletedAt = whiteboard.DeletedAt.DeletedAtValue,
|
||||
MaxParticipants = whiteboard.MaxParticipants.MaxParticipantsValue,
|
||||
JoinPolicy = whiteboard.JoinPolicy,
|
||||
State = whiteboard.State
|
||||
};
|
||||
|
||||
_context.Whiteboards.Add(whiteboardEntity);
|
||||
|
||||
Reference in New Issue
Block a user