Merge pull request #15 from StewKI/feature-refactored-domain
Feature refactored domain
This commit is contained in:
@@ -28,7 +28,7 @@ public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleComm
|
||||
command.EndPositionY,
|
||||
command.BorderThickness);
|
||||
|
||||
await _shapeRepository.Add(rectangle, cancellationToken);
|
||||
await _shapeRepository.SaveAsync(rectangle, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return rectangle.Id;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand, UserI
|
||||
{
|
||||
var user = Domain.Models.User.User.Create(command.Email, command.Username, command.CreatedAt, command.DeletedAt);
|
||||
|
||||
await _userRepository.Save(user, cancellationToken);
|
||||
await _userRepository.SaveAsync(user, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return user.Id;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class CreateWhiteboardCommandHandler : ICommandHandler<CreateWhiteboardCo
|
||||
command.JoinPolicy,
|
||||
command.State);
|
||||
|
||||
await _whiteboardRepository.Save(whiteboard, cancellationToken);
|
||||
await _whiteboardRepository.SaveAsync(whiteboard, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return whiteboard.Id;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CreateWhiteboardMembershipCommandHandler : ICommandHandler<CreateWh
|
||||
command.CanJoin,
|
||||
command.LastInteractedAt);
|
||||
|
||||
await _whiteboardMembershipRepository.Save(whiteboardMembership, cancellationToken);
|
||||
await _whiteboardMembershipRepository.SaveAsync(whiteboardMembership, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return whiteboardMembership.Id;
|
||||
|
||||
26
dotnet/AipsCore/Domain/Abstract/DomainModel.cs
Normal file
26
dotnet/AipsCore/Domain/Abstract/DomainModel.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Abstract;
|
||||
|
||||
public abstract class DomainModel<TId> where TId : DomainId
|
||||
{
|
||||
private readonly List<IDomainEvent> _domainEvents = [];
|
||||
|
||||
public TId Id { get; init; }
|
||||
|
||||
protected DomainModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected DomainModel(TId id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public IReadOnlyList<IDomainEvent> GetDomainEvents() => _domainEvents.ToList();
|
||||
|
||||
public void ClearDomainEvents() => _domainEvents.Clear();
|
||||
|
||||
protected void RaiseDomainEvent(IDomainEvent domainEvent) => _domainEvents.Add(domainEvent);
|
||||
}
|
||||
12
dotnet/AipsCore/Domain/Abstract/IAbstractRepository.cs
Normal file
12
dotnet/AipsCore/Domain/Abstract/IAbstractRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Abstract;
|
||||
|
||||
public interface IAbstractRepository<TModel, in TId>
|
||||
where TModel : DomainModel<TId>
|
||||
where TId : DomainId
|
||||
{
|
||||
Task<TModel?> GetByIdAsync(TId id, CancellationToken cancellationToken = default);
|
||||
Task SaveAsync(TModel model, CancellationToken cancellationToken = default);
|
||||
Task AddAsync(TModel model, CancellationToken cancellationToken = default);
|
||||
}
|
||||
6
dotnet/AipsCore/Domain/Abstract/IDomainEvent.cs
Normal file
6
dotnet/AipsCore/Domain/Abstract/IDomainEvent.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace AipsCore.Domain.Abstract;
|
||||
|
||||
public interface IDomainEvent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Shape.External;
|
||||
|
||||
public interface IShapeRepository
|
||||
public interface IShapeRepository : IAbstractRepository<Shape, ShapeId>
|
||||
{
|
||||
Task<Shape?> Get(ShapeId id, CancellationToken cancellationToken = default);
|
||||
Task Add(Shape shape, CancellationToken cancellationToken = default);
|
||||
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
using AipsCore.Domain.Models.Shape.Enums;
|
||||
using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
@@ -6,10 +7,8 @@ using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Shape;
|
||||
|
||||
public abstract class Shape
|
||||
public abstract class Shape : DomainModel<ShapeId>
|
||||
{
|
||||
public ShapeId Id { get; init; }
|
||||
|
||||
public WhiteboardId WhiteboardId { get; private set; }
|
||||
|
||||
public UserId AuthorId { get; private set; }
|
||||
@@ -21,8 +20,8 @@ public abstract class Shape
|
||||
public Color Color { get; private set; }
|
||||
|
||||
protected Shape(ShapeId id, WhiteboardId whiteboardId, UserId authorId, Position position, Color color)
|
||||
: base(id)
|
||||
{
|
||||
Id = id;
|
||||
Position = position;
|
||||
Color = color;
|
||||
AuthorId = authorId;
|
||||
@@ -35,10 +34,10 @@ public abstract class Shape
|
||||
int positionX, int positionY,
|
||||
string color, UserId authorId)
|
||||
{
|
||||
AuthorId = authorId;
|
||||
Id = new ShapeId(id);
|
||||
Position = new Position(positionX, positionY);
|
||||
Color = new Color(color);
|
||||
AuthorId = authorId;
|
||||
WhiteboardId = new WhiteboardId(whiteboardId);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.User.External;
|
||||
|
||||
public interface IUserRepository
|
||||
public interface IUserRepository : IAbstractRepository<User, UserId>
|
||||
{
|
||||
Task<User?> Get(UserId userId, CancellationToken cancellationToken = default);
|
||||
Task Save(User user, CancellationToken cancellationToken = default);
|
||||
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.User;
|
||||
|
||||
public class User
|
||||
public class User : DomainModel<UserId>
|
||||
{
|
||||
public UserId Id { get; private set; }
|
||||
public Email Email { get; private set; }
|
||||
public Username Username { get; private set; }
|
||||
public UserCreatedAt CreatedAt { get; private set; }
|
||||
public UserDeletedAt DeletedAt { get; private set; }
|
||||
|
||||
public User(UserId id, Email email, Username username, UserCreatedAt createdAt, UserDeletedAt deletedAt)
|
||||
: base(id)
|
||||
{
|
||||
Id = id;
|
||||
Email = email;
|
||||
Username = username;
|
||||
CreatedAt = createdAt;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Whiteboard.External;
|
||||
|
||||
public interface IWhiteboardRepository
|
||||
public interface IWhiteboardRepository : IAbstractRepository<Whiteboard, WhiteboardId>
|
||||
{
|
||||
Task<Whiteboard?> Get(WhiteboardId whiteboardId, CancellationToken cancellationToken = default);
|
||||
Task Save(Whiteboard whiteboard, CancellationToken cancellationToken = default);
|
||||
Task<bool> WhiteboardCodeExists(WhiteboardCode whiteboardCode);
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.Enums;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.Whiteboard;
|
||||
|
||||
public class Whiteboard
|
||||
public class Whiteboard : DomainModel<WhiteboardId>
|
||||
{
|
||||
public WhiteboardId Id { get; private set; }
|
||||
public UserId WhiteboardOwnerId { get; private set; }
|
||||
public WhiteboardCode Code { get; private set; }
|
||||
public WhiteboardTitle Title { get; private set; }
|
||||
@@ -26,8 +26,8 @@ public class Whiteboard
|
||||
WhiteboardMaxParticipants maxParticipants,
|
||||
WhiteboardJoinPolicy joinPolicy,
|
||||
WhiteboardState state)
|
||||
: base(id)
|
||||
{
|
||||
Id = id;
|
||||
WhiteboardOwnerId = whiteboardOwner.Id;
|
||||
Code = code;
|
||||
Title = title;
|
||||
@@ -48,8 +48,8 @@ public class Whiteboard
|
||||
WhiteboardMaxParticipants maxParticipants,
|
||||
WhiteboardJoinPolicy joinPolicy,
|
||||
WhiteboardState state)
|
||||
: base(id)
|
||||
{
|
||||
Id = id;
|
||||
WhiteboardOwnerId = whiteboardOwnerId;
|
||||
Code = code;
|
||||
Title = title;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.WhiteboardMembership.External;
|
||||
|
||||
public interface IWhiteboardMembershipRepository
|
||||
public interface IWhiteboardMembershipRepository : IAbstractRepository<WhiteboardMembership, WhiteboardMembershipId>
|
||||
{
|
||||
Task<WhiteboardMembership?> Get(WhiteboardMembershipId whiteboardMembershipId, CancellationToken cancellationToken = default);
|
||||
Task Save(WhiteboardMembership whiteboardMembership, CancellationToken cancellationToken = default);
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Models.WhiteboardMembership;
|
||||
|
||||
public class WhiteboardMembership
|
||||
public class WhiteboardMembership : DomainModel<WhiteboardMembershipId>
|
||||
{
|
||||
public WhiteboardMembershipId Id { get; private set; }
|
||||
public WhiteboardId WhiteboardId { get; private set; }
|
||||
public UserId UserId { get; private set; }
|
||||
public WhiteboardMembershipIsBanned IsBanned { get; private set; }
|
||||
@@ -22,8 +22,8 @@ public class WhiteboardMembership
|
||||
WhiteboardMembershipEditingEnabled editingEnabled,
|
||||
WhiteboardMembershipCanJoin canJoin,
|
||||
WhiteboardMembershipLastInteractedAt lastInteractedAt)
|
||||
: base(id)
|
||||
{
|
||||
Id = id;
|
||||
WhiteboardId = owner.Id;
|
||||
UserId = user.Id;
|
||||
IsBanned = isBanned;
|
||||
@@ -40,8 +40,8 @@ public class WhiteboardMembership
|
||||
WhiteboardMembershipEditingEnabled editingEnabled,
|
||||
WhiteboardMembershipCanJoin canJoin,
|
||||
WhiteboardMembershipLastInteractedAt lastInteractedAt)
|
||||
: base(id)
|
||||
{
|
||||
Id = id;
|
||||
WhiteboardId = ownerId;
|
||||
UserId = userId;
|
||||
IsBanned = isBanned;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
using AipsCore.Infrastructure.Persistence.Db;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AipsCore.Infrastructure.Persistence.Abstract;
|
||||
|
||||
public abstract class AbstractRepository<TModel, TId, TEntity> : IAbstractRepository<TModel, TId>
|
||||
where TModel : DomainModel<TId>
|
||||
where TId : DomainId
|
||||
where TEntity : class
|
||||
{
|
||||
protected readonly AipsDbContext Context;
|
||||
protected readonly DbSet<TEntity> DbSet;
|
||||
|
||||
protected AbstractRepository(AipsDbContext context)
|
||||
{
|
||||
Context = context;
|
||||
DbSet = Context.Set<TEntity>();
|
||||
}
|
||||
|
||||
public async Task<TModel?> GetByIdAsync(TId id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await DbSet.FindAsync([new Guid(id.IdValue)], cancellationToken);
|
||||
|
||||
return entity != null ? MapToModel(entity) : null;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(TModel model, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await DbSet.FindAsync([new Guid(model.Id.IdValue)], cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
entity = MapToEntity(model);
|
||||
await DbSet.AddAsync(entity, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateEntity(entity, model);
|
||||
DbSet.Update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task AddAsync(TModel model, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = MapToEntity(model);
|
||||
|
||||
await DbSet.AddAsync(entity, cancellationToken);
|
||||
}
|
||||
|
||||
protected abstract TModel MapToModel(TEntity entity);
|
||||
protected abstract TEntity MapToEntity(TModel model);
|
||||
protected abstract void UpdateEntity(TEntity entity, TModel model);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace AipsCore.Infrastructure.Persistence.Shape.Mappers;
|
||||
|
||||
public static partial class ShapeMappers
|
||||
{
|
||||
public static Domain.Models.Shape.Shape EntityToModel(Shape shape)
|
||||
public static Domain.Models.Shape.Shape MapToEntity(Shape shape)
|
||||
{
|
||||
return shape.Type switch
|
||||
{
|
||||
@@ -30,7 +30,7 @@ public static partial class ShapeMappers
|
||||
shape.EndPositionX!.Value, shape.EndPositionY!.Value,
|
||||
shape.Thickness!.Value);
|
||||
}
|
||||
|
||||
|
||||
public static Line EntityToLine(Shape shape)
|
||||
{
|
||||
return Line.Create(
|
||||
@@ -42,7 +42,7 @@ public static partial class ShapeMappers
|
||||
shape.EndPositionX!.Value, shape.EndPositionY!.Value,
|
||||
shape.Thickness!.Value);
|
||||
}
|
||||
|
||||
|
||||
public static Arrow EntityToArrow(Shape shape)
|
||||
{
|
||||
return Arrow.Create(
|
||||
@@ -54,7 +54,7 @@ public static partial class ShapeMappers
|
||||
shape.EndPositionX!.Value, shape.EndPositionY!.Value,
|
||||
shape.Thickness!.Value);
|
||||
}
|
||||
|
||||
|
||||
public static TextShape EntityToTextShape(Shape shape)
|
||||
{
|
||||
return TextShape.Create(
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace AipsCore.Infrastructure.Persistence.Shape.Mappers;
|
||||
public static partial class ShapeMappers
|
||||
{
|
||||
|
||||
public static Shape ModelToEntity(Domain.Models.Shape.Shape model)
|
||||
public static Shape MapToEntity(Domain.Models.Shape.Shape model)
|
||||
{
|
||||
return model.ShapeType switch
|
||||
{
|
||||
@@ -23,7 +23,7 @@ public static partial class ShapeMappers
|
||||
|
||||
public static Shape RectangleToEntity(Rectangle rectangle)
|
||||
{
|
||||
return new Shape()
|
||||
return new Shape
|
||||
{
|
||||
Id = new Guid(rectangle.Id.Value),
|
||||
Type = rectangle.ShapeType,
|
||||
@@ -37,10 +37,10 @@ public static partial class ShapeMappers
|
||||
Thickness = rectangle.BorderThickness.Value,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static Shape LineToEntity(Line line)
|
||||
{
|
||||
return new Shape()
|
||||
return new Shape
|
||||
{
|
||||
Id = new Guid(line.Id.Value),
|
||||
Type = line.ShapeType,
|
||||
@@ -54,10 +54,10 @@ public static partial class ShapeMappers
|
||||
Thickness = line.Thickness.Value,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static Shape ArrowToEntity(Arrow arrow)
|
||||
{
|
||||
return new Shape()
|
||||
return new Shape
|
||||
{
|
||||
Id = new Guid(arrow.Id.Value),
|
||||
Type = arrow.ShapeType,
|
||||
@@ -71,10 +71,10 @@ public static partial class ShapeMappers
|
||||
Thickness = arrow.Thickness.Value,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static Shape TextShapeToEntity(TextShape textShape)
|
||||
{
|
||||
return new Shape()
|
||||
return new Shape
|
||||
{
|
||||
Id = new Guid(textShape.Id.Value),
|
||||
Type = textShape.ShapeType,
|
||||
|
||||
@@ -38,7 +38,7 @@ public static partial class ShapeMappers
|
||||
entity.EndPositionY = rectangle.EndPosition.Y;
|
||||
entity.Thickness = rectangle.BorderThickness.Value;
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateEntityFromLine(Shape entity, Line line)
|
||||
{
|
||||
entity.EndPositionX = line.EndPosition.X;
|
||||
@@ -52,7 +52,7 @@ public static partial class ShapeMappers
|
||||
entity.EndPositionY = arrow.EndPosition.Y;
|
||||
entity.Thickness = arrow.Thickness.Value;
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateEntityFromTextShape(Shape entity, TextShape textShape)
|
||||
{
|
||||
entity.TextValue = textShape.TextShapeValue.Text;
|
||||
|
||||
@@ -1,42 +1,31 @@
|
||||
using AipsCore.Domain.Models.Shape.External;
|
||||
using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
using AipsCore.Infrastructure.Persistence.Abstract;
|
||||
using AipsCore.Infrastructure.Persistence.Db;
|
||||
using AipsCore.Infrastructure.Persistence.Shape.Mappers;
|
||||
|
||||
namespace AipsCore.Infrastructure.Persistence.Shape;
|
||||
|
||||
public class ShapeRepository : IShapeRepository
|
||||
public class ShapeRepository : AbstractRepository<Domain.Models.Shape.Shape, ShapeId, Shape>, IShapeRepository
|
||||
{
|
||||
private readonly AipsDbContext _context;
|
||||
|
||||
public ShapeRepository(AipsDbContext context)
|
||||
public ShapeRepository(AipsDbContext context)
|
||||
: base(context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Domain.Models.Shape.Shape?> Get(ShapeId id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _context.Shapes.FindAsync([new Guid(id.Value)], cancellationToken);
|
||||
|
||||
if (entity is null) return null;
|
||||
|
||||
return ShapeMappers.EntityToModel(entity);
|
||||
}
|
||||
|
||||
public async Task Add(Domain.Models.Shape.Shape shape, CancellationToken cancellationToken = default)
|
||||
protected override Domain.Models.Shape.Shape MapToModel(Shape entity)
|
||||
{
|
||||
var entity = await _context.Shapes.FindAsync([new Guid(shape.Id.Value)], cancellationToken);
|
||||
return ShapeMappers.MapToEntity(entity);
|
||||
}
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
ShapeMappers.UpdateEntity(entity, shape);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newEntity = ShapeMappers.ModelToEntity(shape);
|
||||
|
||||
await _context.Shapes.AddAsync(newEntity, cancellationToken);
|
||||
}
|
||||
protected override Shape MapToEntity(Domain.Models.Shape.Shape model)
|
||||
{
|
||||
return ShapeMappers.MapToEntity(model);
|
||||
}
|
||||
|
||||
protected override void UpdateEntity(Shape entity, Domain.Models.Shape.Shape model)
|
||||
{
|
||||
ShapeMappers.UpdateEntity(entity, model);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +1,45 @@
|
||||
using AipsCore.Domain.Models.User.External;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
using AipsCore.Infrastructure.Persistence.Abstract;
|
||||
using AipsCore.Infrastructure.Persistence.Db;
|
||||
|
||||
namespace AipsCore.Infrastructure.Persistence.User;
|
||||
|
||||
public class UserRepository : IUserRepository
|
||||
public class UserRepository : AbstractRepository<Domain.Models.User.User, UserId, User>, IUserRepository
|
||||
{
|
||||
private readonly AipsDbContext _context;
|
||||
|
||||
public UserRepository(AipsDbContext context)
|
||||
public UserRepository(AipsDbContext context)
|
||||
: base(context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Domain.Models.User.User?> Get(UserId userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var userEntity = await _context.Users.FindAsync([new Guid(userId.IdValue), cancellationToken], cancellationToken: cancellationToken);
|
||||
|
||||
if (userEntity is null) return null;
|
||||
|
||||
protected override Domain.Models.User.User MapToModel(User entity)
|
||||
{
|
||||
return Domain.Models.User.User.Create(
|
||||
userEntity.Id.ToString(),
|
||||
userEntity.Email,
|
||||
userEntity.Username,
|
||||
userEntity.CreatedAt,
|
||||
userEntity.DeletedAt);
|
||||
entity.Id.ToString(),
|
||||
entity.Email,
|
||||
entity.Username,
|
||||
entity.CreatedAt,
|
||||
entity.DeletedAt
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Save(Domain.Models.User.User user, CancellationToken cancellationToken = default)
|
||||
protected override User MapToEntity(Domain.Models.User.User model)
|
||||
{
|
||||
// ReSharper disable once MethodSupportsCancellation
|
||||
var userEntity = await _context.Users.FindAsync(new Guid(user.Id.IdValue));
|
||||
return new User
|
||||
{
|
||||
Id = new Guid(model.Id.IdValue),
|
||||
Email = model.Email.EmailValue,
|
||||
Username = model.Username.UsernameValue,
|
||||
CreatedAt = model.CreatedAt.CreatedAtValue,
|
||||
DeletedAt = model.DeletedAt.DeletedAtValue
|
||||
};
|
||||
}
|
||||
|
||||
if (userEntity is not null)
|
||||
{
|
||||
userEntity.Email = user.Email.EmailValue;
|
||||
userEntity.Username = user.Username.UsernameValue;
|
||||
userEntity.CreatedAt = user.CreatedAt.CreatedAtValue;
|
||||
userEntity.DeletedAt = user.DeletedAt.DeletedAtValue;
|
||||
|
||||
_context.Users.Update(userEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
userEntity = new User()
|
||||
{
|
||||
Id = new Guid(user.Id.IdValue),
|
||||
Email = user.Email.EmailValue,
|
||||
Username = user.Username.UsernameValue,
|
||||
CreatedAt = user.CreatedAt.CreatedAtValue,
|
||||
DeletedAt = user.DeletedAt.DeletedAtValue
|
||||
};
|
||||
|
||||
_context.Users.Add(userEntity);
|
||||
}
|
||||
protected override void UpdateEntity(User entity, Domain.Models.User.User model)
|
||||
{
|
||||
entity.Email = model.Email.EmailValue;
|
||||
entity.Username = model.Username.UsernameValue;
|
||||
entity.CreatedAt = model.CreatedAt.CreatedAtValue;
|
||||
entity.DeletedAt = model.DeletedAt.DeletedAtValue;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,64 @@
|
||||
using AipsCore.Domain.Models.Whiteboard.External;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
using AipsCore.Infrastructure.Persistence.Abstract;
|
||||
using AipsCore.Infrastructure.Persistence.Db;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AipsCore.Infrastructure.Persistence.Whiteboard;
|
||||
|
||||
public class WhiteboardRepository : IWhiteboardRepository
|
||||
public class WhiteboardRepository
|
||||
: AbstractRepository<Domain.Models.Whiteboard.Whiteboard, WhiteboardId, Whiteboard>, IWhiteboardRepository
|
||||
{
|
||||
private readonly AipsDbContext _context;
|
||||
|
||||
public WhiteboardRepository(AipsDbContext context)
|
||||
public WhiteboardRepository(AipsDbContext context)
|
||||
: base(context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
}
|
||||
|
||||
public async Task<Domain.Models.Whiteboard.Whiteboard?> Get(WhiteboardId whiteboardId, CancellationToken cancellationToken = default)
|
||||
|
||||
protected override Domain.Models.Whiteboard.Whiteboard MapToModel(Whiteboard entity)
|
||||
{
|
||||
var whiteboardEntity = await _context.Whiteboards.FindAsync([new Guid(whiteboardId.IdValue), cancellationToken], cancellationToken: cancellationToken);
|
||||
|
||||
if (whiteboardEntity is null) return null;
|
||||
|
||||
return Domain.Models.Whiteboard.Whiteboard.Create(
|
||||
whiteboardEntity.Id.ToString(),
|
||||
whiteboardEntity.OwnerId.ToString(),
|
||||
whiteboardEntity.Code,
|
||||
whiteboardEntity.Title,
|
||||
whiteboardEntity.CreatedAt,
|
||||
whiteboardEntity.DeletedAt,
|
||||
whiteboardEntity.MaxParticipants,
|
||||
whiteboardEntity.JoinPolicy,
|
||||
whiteboardEntity.State);
|
||||
entity.Id.ToString(),
|
||||
entity.OwnerId.ToString(),
|
||||
entity.Code,
|
||||
entity.Title,
|
||||
entity.CreatedAt,
|
||||
entity.DeletedAt,
|
||||
entity.MaxParticipants,
|
||||
entity.JoinPolicy,
|
||||
entity.State
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Save(Domain.Models.Whiteboard.Whiteboard whiteboard, CancellationToken cancellationToken = default)
|
||||
protected override Whiteboard MapToEntity(Domain.Models.Whiteboard.Whiteboard model)
|
||||
{
|
||||
var whiteboardEntity = await _context.Whiteboards.FindAsync(new Guid(whiteboard.Id.IdValue));
|
||||
|
||||
if (whiteboardEntity is not null)
|
||||
return new Whiteboard
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
whiteboardEntity = new Whiteboard()
|
||||
{
|
||||
Id = new Guid(whiteboard.Id.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);
|
||||
}
|
||||
Id = new Guid(model.Id.IdValue),
|
||||
OwnerId = new Guid(model.WhiteboardOwnerId.IdValue),
|
||||
Code = model.Code.CodeValue,
|
||||
Title = model.Title.TitleValue,
|
||||
CreatedAt = model.CreatedAt.CreatedAtValue,
|
||||
DeletedAt = model.DeletedAt.DeletedAtValue,
|
||||
MaxParticipants = model.MaxParticipants.MaxParticipantsValue,
|
||||
JoinPolicy = model.JoinPolicy,
|
||||
State = model.State
|
||||
};
|
||||
}
|
||||
|
||||
protected override void UpdateEntity(Whiteboard entity, Domain.Models.Whiteboard.Whiteboard model)
|
||||
{
|
||||
entity.Code = model.Code.CodeValue;
|
||||
entity.Title = model.Title.TitleValue;
|
||||
entity.CreatedAt = model.CreatedAt.CreatedAtValue;
|
||||
entity.DeletedAt = model.DeletedAt.DeletedAtValue;
|
||||
entity.MaxParticipants = model.MaxParticipants.MaxParticipantsValue;
|
||||
entity.JoinPolicy = model.JoinPolicy;
|
||||
entity.State = model.State;
|
||||
}
|
||||
|
||||
public async Task<bool> WhiteboardCodeExists(WhiteboardCode whiteboardCode)
|
||||
{
|
||||
var codeExists = await _context.Whiteboards.AnyAsync(w => w.Code == whiteboardCode.CodeValue);
|
||||
return codeExists;
|
||||
return await Context.Whiteboards.AnyAsync(w => w.Code == whiteboardCode.CodeValue);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,52 @@
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.External;
|
||||
using AipsCore.Domain.Models.WhiteboardMembership.ValueObjects;
|
||||
using AipsCore.Infrastructure.Persistence.Abstract;
|
||||
using AipsCore.Infrastructure.Persistence.Db;
|
||||
|
||||
namespace AipsCore.Infrastructure.Persistence.WhiteboardMembership;
|
||||
|
||||
public class WhiteboardMembershipRepository : IWhiteboardMembershipRepository
|
||||
public class WhiteboardMembershipRepository
|
||||
: AbstractRepository<Domain.Models.WhiteboardMembership.WhiteboardMembership, WhiteboardMembershipId, WhiteboardMembership>,
|
||||
IWhiteboardMembershipRepository
|
||||
{
|
||||
private readonly AipsDbContext _context;
|
||||
|
||||
public WhiteboardMembershipRepository(AipsDbContext context)
|
||||
: base(context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Domain.Models.WhiteboardMembership.WhiteboardMembership?> Get(WhiteboardMembershipId whiteboardMembershipId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var whiteboardMembershipEntity = await _context.WhiteboardMemberships.FindAsync(new Guid(whiteboardMembershipId.IdValue));
|
||||
|
||||
if (whiteboardMembershipEntity is null) return null;
|
||||
}
|
||||
|
||||
protected override Domain.Models.WhiteboardMembership.WhiteboardMembership MapToModel(WhiteboardMembership entity)
|
||||
{
|
||||
return Domain.Models.WhiteboardMembership.WhiteboardMembership.Create(
|
||||
whiteboardMembershipEntity.Id.ToString(),
|
||||
whiteboardMembershipEntity.WhiteboardId.ToString(),
|
||||
whiteboardMembershipEntity.UserId.ToString(),
|
||||
whiteboardMembershipEntity.IsBanned,
|
||||
whiteboardMembershipEntity.EditingEnabled,
|
||||
whiteboardMembershipEntity.CanJoin,
|
||||
whiteboardMembershipEntity.LastInteractedAt);
|
||||
entity.Id.ToString(),
|
||||
entity.WhiteboardId.ToString(),
|
||||
entity.UserId.ToString(),
|
||||
entity.IsBanned,
|
||||
entity.EditingEnabled,
|
||||
entity.CanJoin,
|
||||
entity.LastInteractedAt
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Save(Domain.Models.WhiteboardMembership.WhiteboardMembership whiteboardMembership, CancellationToken cancellationToken = default)
|
||||
protected override WhiteboardMembership MapToEntity(Domain.Models.WhiteboardMembership.WhiteboardMembership model)
|
||||
{
|
||||
var whiteboardMembershipEntity = await _context.WhiteboardMemberships.FindAsync(new Guid(whiteboardMembership.Id.IdValue));
|
||||
|
||||
if (whiteboardMembershipEntity is not null)
|
||||
return new WhiteboardMembership
|
||||
{
|
||||
whiteboardMembershipEntity.IsBanned = whiteboardMembership.IsBanned.IsBannedValue;
|
||||
whiteboardMembershipEntity.EditingEnabled = whiteboardMembership.EditingEnabled.EditingEnabledValue;
|
||||
whiteboardMembershipEntity.CanJoin = whiteboardMembership.CanJoin.CanJoinValue;
|
||||
whiteboardMembershipEntity.LastInteractedAt = whiteboardMembership.LastInteractedAt.LastInteractedAtValue;
|
||||
|
||||
_context.Update(whiteboardMembershipEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
whiteboardMembershipEntity = new WhiteboardMembership()
|
||||
{
|
||||
Id = new Guid(whiteboardMembership.Id.IdValue),
|
||||
WhiteboardId = new Guid(whiteboardMembership.WhiteboardId.IdValue),
|
||||
Whiteboard = null,
|
||||
UserId = new Guid(whiteboardMembership.UserId.IdValue),
|
||||
User = null,
|
||||
IsBanned = whiteboardMembership.IsBanned.IsBannedValue,
|
||||
EditingEnabled = whiteboardMembership.EditingEnabled.EditingEnabledValue,
|
||||
CanJoin = whiteboardMembership.CanJoin.CanJoinValue,
|
||||
LastInteractedAt = whiteboardMembership.LastInteractedAt.LastInteractedAtValue
|
||||
};
|
||||
|
||||
_context.Add(whiteboardMembershipEntity);
|
||||
}
|
||||
Id = new Guid(model.Id.IdValue),
|
||||
WhiteboardId = new Guid(model.WhiteboardId.IdValue),
|
||||
UserId = new Guid(model.UserId.IdValue),
|
||||
IsBanned = model.IsBanned.IsBannedValue,
|
||||
EditingEnabled = model.EditingEnabled.EditingEnabledValue,
|
||||
CanJoin = model.CanJoin.CanJoinValue,
|
||||
LastInteractedAt = model.LastInteractedAt.LastInteractedAtValue
|
||||
};
|
||||
}
|
||||
|
||||
protected override void UpdateEntity(WhiteboardMembership entity, Domain.Models.WhiteboardMembership.WhiteboardMembership model)
|
||||
{
|
||||
entity.IsBanned = model.IsBanned.IsBannedValue;
|
||||
entity.EditingEnabled = model.EditingEnabled.EditingEnabledValue;
|
||||
entity.CanJoin = model.CanJoin.CanJoinValue;
|
||||
entity.LastInteractedAt = model.LastInteractedAt.LastInteractedAtValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user