-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate creation of an Identity and registration of a Device domain a…
…ppropriate logic from Handler to Domain (#886) * fix: use postgres connection string * refactore: extract methods in handler * wip * wip * fix: add device id * feat: introduce AddDevice() * refactor: improve code structure of Handler * fix: resolve DeviceId issue * refactor: do not pass ApplicationUser in handler * feat: remove prop * refactor: extract method * feat: add new method * refactor: improve constructor * refactor: improe code structure of Handler * refactor: small improvements * test: add new param * refactor: improve ApplicationUser * refactor: improve code structure * fix: resolve foreign key constraint * test: add communication language to integration test * chore: fix formatting issues * test: use new ctor * fix: use correct language in test * fix: update test * refactor: small improvements * fix: resolve errors that prevented the db population * feat: introduce validator * feat: use validator * refactor: add various small improvements * test: improve test * refactor: use IsValid() instead of Validate() * feat: remove IsValid() * refactor: various small improvements * fix: use correct type * fix: reverte IsValid() changes * chore: remove unused InvalidCommunicationLanguageException class * refactor: remove unnecessary class --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Timo Notheisen <[email protected]>
- Loading branch information
1 parent
141acd7
commit 35c8a8f
Showing
30 changed files
with
163 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 17 additions & 3 deletions
20
...ices/src/Devices.Application/Identities/Commands/CreateIdentity/CreateIdentityResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 7 additions & 34 deletions
41
Modules/Devices/src/Devices.Application/Users/Commands/SeedTestUsers/Handler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,32 @@ | ||
using Backbone.DevelopmentKit.Identity.ValueObjects; | ||
using Backbone.Modules.Devices.Application.Infrastructure.Persistence.Database; | ||
using Backbone.Modules.Devices.Application.Infrastructure.Persistence.Repository; | ||
using Backbone.Modules.Devices.Domain.Entities.Identities; | ||
using Backbone.Tooling; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Backbone.Modules.Devices.Application.Users.Commands.SeedTestUsers; | ||
|
||
public class Handler : IRequestHandler<SeedTestUsersCommand> | ||
{ | ||
private readonly IPasswordHasher<ApplicationUser> _passwordHasher; | ||
private readonly ApplicationOptions _applicationOptions; | ||
private readonly IDevicesDbContext _dbContext; | ||
private readonly IIdentitiesRepository _identitiesRepository; | ||
private readonly ITiersRepository _tiersRepository; | ||
|
||
public Handler(IDevicesDbContext context, ITiersRepository tiersRepository, IPasswordHasher<ApplicationUser> passwordHasher, IOptions<ApplicationOptions> applicationOptions) | ||
public Handler(IIdentitiesRepository identitiesRepository, ITiersRepository tiersRepository, IOptions<ApplicationOptions> applicationOptions) | ||
{ | ||
_dbContext = context; | ||
_identitiesRepository = identitiesRepository; | ||
_tiersRepository = tiersRepository; | ||
_passwordHasher = passwordHasher; | ||
_applicationOptions = applicationOptions.Value; | ||
} | ||
|
||
public async Task Handle(SeedTestUsersCommand request, CancellationToken cancellationToken) | ||
{ | ||
var basicTier = await _tiersRepository.FindBasicTier(cancellationToken); | ||
|
||
var user = new ApplicationUser(new Device(new Identity("test", | ||
IdentityAddress.Create([1, 1, 1, 1, 1], _applicationOptions.DidDomainName), | ||
[1, 1, 1, 1, 1], basicTier!.Id, 1 | ||
), CommunicationLanguage.DEFAULT_LANGUAGE)) | ||
{ | ||
SecurityStamp = Guid.NewGuid().ToString("D"), | ||
UserName = "USRa", | ||
NormalizedUserName = "USRA", | ||
CreatedAt = SystemTime.UtcNow | ||
}; | ||
user.PasswordHash = _passwordHasher.HashPassword(user, "a"); | ||
await _dbContext.Set<ApplicationUser>().AddAsync(user, cancellationToken); | ||
var identityA = Identity.CreateTestIdentity(IdentityAddress.Create([1, 1, 1, 1, 1], _applicationOptions.DidDomainName), [1, 1, 1, 1, 1], basicTier!.Id, "USRa"); | ||
var identityB = Identity.CreateTestIdentity(IdentityAddress.Create([2, 2, 2, 2, 2], _applicationOptions.DidDomainName), [2, 2, 2, 2, 2], basicTier.Id, "USRb"); | ||
|
||
user = new ApplicationUser(new Device(new Identity("test", | ||
IdentityAddress.Create([2, 2, 2, 2, 2], _applicationOptions.DidDomainName), | ||
[2, 2, 2, 2, 2], basicTier.Id, 1 | ||
), CommunicationLanguage.DEFAULT_LANGUAGE)) | ||
{ | ||
SecurityStamp = Guid.NewGuid().ToString("D"), | ||
UserName = "USRb", | ||
NormalizedUserName = "USRB", | ||
CreatedAt = SystemTime.UtcNow | ||
}; | ||
user.PasswordHash = _passwordHasher.HashPassword(user, "b"); | ||
await _dbContext.Set<ApplicationUser>().AddAsync(user, cancellationToken); | ||
|
||
await _dbContext.SaveChangesAsync(cancellationToken); | ||
await _identitiesRepository.Add(identityA, "a"); | ||
await _identitiesRepository.Add(identityB, "b"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.