diff --git a/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommand.cs b/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommand.cs index 3276be2..56c696f 100644 --- a/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommand.cs +++ b/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommand.cs @@ -3,4 +3,9 @@ using AipsCore.Domain.Models.User.ValueObjects; namespace AipsCore.Application.Models.User.Command.CreateUser; -public record CreateUserCommand(string Username, string Email) : ICommand; \ No newline at end of file +public record CreateUserCommand( + string Username, + string Email, + DateTime CreatedAt, + DateTime DeletedAt) + : ICommand; \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommandHandler.cs b/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommandHandler.cs index 84b33fa..ea004af 100644 --- a/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommandHandler.cs +++ b/dotnet/AipsCore/Application/Models/User/Command/CreateUser/CreateUserCommandHandler.cs @@ -18,7 +18,7 @@ public class CreateUserCommandHandler : ICommandHandler Handle(CreateUserCommand command, CancellationToken cancellationToken = default) { - var user = Domain.Models.User.User.Create(command.Email, command.Username); + var user = Domain.Models.User.User.Create(command.Email, command.Username, command.CreatedAt, command.DeletedAt); await _userRepository.Save(user, cancellationToken); await _unitOfWork.SaveChangesAsync(cancellationToken); diff --git a/dotnet/AipsCore/Domain/Models/User/User.cs b/dotnet/AipsCore/Domain/Models/User/User.cs index 416f102..aa7aac9 100644 --- a/dotnet/AipsCore/Domain/Models/User/User.cs +++ b/dotnet/AipsCore/Domain/Models/User/User.cs @@ -8,26 +8,36 @@ public class User 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) + public User(UserId id, Email email, Username username, UserCreatedAt createdAt, UserDeletedAt deletedAt) { Id = id; Email = email; Username = username; + CreatedAt = createdAt; + DeletedAt = deletedAt; } - public static User Create(string id, string email, string username) + public static User Create(string id, string email, string username, DateTime createdAt, DateTime? deletedAt) { var userIdVo = new UserId(id); var usernameVo = new Username(username); var emailVo = new Email(email); - return new User( userIdVo, emailVo, usernameVo); + var createdAtVo = new UserCreatedAt(createdAt); + var deletedAtVo = new UserDeletedAt(deletedAt); + + return new User(userIdVo, emailVo, usernameVo, createdAtVo, deletedAtVo); } - public static User Create(string email, string username) + public static User Create(string email, string username, DateTime createdAt, DateTime? deletedAt) { var usernameVo = new Username(username); var emailVo = new Email(email); - return new User( UserId.Any(), emailVo, usernameVo); + var createdAtVo = new UserCreatedAt(createdAt); + var deletedAtVo = new UserDeletedAt(deletedAt); + + return new User(UserId.Any(), emailVo, usernameVo, createdAtVo, deletedAtVo); } } \ No newline at end of file diff --git a/dotnet/AipsCore/Domain/Models/User/ValueObjects/UserCreatedAt.cs b/dotnet/AipsCore/Domain/Models/User/ValueObjects/UserCreatedAt.cs new file mode 100644 index 0000000..bde200a --- /dev/null +++ b/dotnet/AipsCore/Domain/Models/User/ValueObjects/UserCreatedAt.cs @@ -0,0 +1,23 @@ +using AipsCore.Domain.Abstract.Rule; +using AipsCore.Domain.Abstract.ValueObject; +using AipsCore.Domain.Common.Validation.Rules; + +namespace AipsCore.Domain.Models.User.ValueObjects; + +public record UserCreatedAt : AbstractValueObject +{ + public DateTime CreatedAtValue { get; private set; } + + public UserCreatedAt(DateTime CreatedAtValue) + { + this.CreatedAtValue = CreatedAtValue; + Validate(); + } + + protected override ICollection GetValidationRules() + { + return [ + new DateInPastRule(CreatedAtValue) + ]; + } +} \ No newline at end of file diff --git a/dotnet/AipsCore/Domain/Models/User/ValueObjects/UserDeletedAt.cs b/dotnet/AipsCore/Domain/Models/User/ValueObjects/UserDeletedAt.cs new file mode 100644 index 0000000..ad80605 --- /dev/null +++ b/dotnet/AipsCore/Domain/Models/User/ValueObjects/UserDeletedAt.cs @@ -0,0 +1,23 @@ +using AipsCore.Domain.Abstract.Rule; +using AipsCore.Domain.Abstract.ValueObject; +using AipsCore.Domain.Common.Validation.Rules; + +namespace AipsCore.Domain.Models.User.ValueObjects; + +public record UserDeletedAt : AbstractValueObject +{ + public DateTime? DeletedAtValue { get; private set; } + + public UserDeletedAt(DateTime? DeletedAtValue) + { + this.DeletedAtValue = DeletedAtValue; + Validate(); + } + + protected override ICollection GetValidationRules() + { + return [ + new DateInPastRule(DeletedAtValue) + ]; + } +} \ No newline at end of file diff --git a/dotnet/AipsCore/Infrastructure/Persistence/User/User.cs b/dotnet/AipsCore/Infrastructure/Persistence/User/User.cs index 6cf01fc..1e5c9d0 100644 --- a/dotnet/AipsCore/Infrastructure/Persistence/User/User.cs +++ b/dotnet/AipsCore/Infrastructure/Persistence/User/User.cs @@ -7,6 +7,16 @@ public class User { [Key] public Guid Id { get; set; } - [Required] [MaxLength(255)] public string Username { get; set; } = null!; - [Required] [MaxLength(255)] public string Email { get; set; } = null!; + + [Required] + [MaxLength(255)] + public string Username { get; set; } = null!; + + [Required] + [MaxLength(255)] + public string Email { get; set; } = null!; + + public DateTime CreatedAt { get; set; } + + public DateTime? DeletedAt { get; set; } } \ No newline at end of file diff --git a/dotnet/AipsCore/Infrastructure/Persistence/User/UserRepository.cs b/dotnet/AipsCore/Infrastructure/Persistence/User/UserRepository.cs index b33ab48..9db91e3 100644 --- a/dotnet/AipsCore/Infrastructure/Persistence/User/UserRepository.cs +++ b/dotnet/AipsCore/Infrastructure/Persistence/User/UserRepository.cs @@ -22,7 +22,9 @@ public class UserRepository : IUserRepository return Domain.Models.User.User.Create( userEntity.Id.ToString(), userEntity.Email, - userEntity.Username); + userEntity.Username, + userEntity.CreatedAt, + userEntity.DeletedAt); } public async Task Save(Domain.Models.User.User user, CancellationToken cancellationToken = default) @@ -34,6 +36,8 @@ public class UserRepository : IUserRepository { userEntity.Email = user.Email.EmailValue; userEntity.Username = user.Username.UsernameValue; + userEntity.CreatedAt = user.CreatedAt.CreatedAtValue; + userEntity.DeletedAt = user.DeletedAt.DeletedAtValue; _context.Users.Update(userEntity); } @@ -44,6 +48,8 @@ public class UserRepository : IUserRepository 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);