Skip to content

Commit

Permalink
readded builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
BeierKevin committed Apr 29, 2024
1 parent a94ad80 commit 2b34597
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/KeyVaultCli.Domain/Entities/Vault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public void AddPasswordEntry(string serviceName, string accountName, string pass
{
var encryptedPassword = _vaultEncryptionService.Encrypt(password, _masterPassword);

var entry = new PasswordEntry
{
ServiceName = serviceName,
AccountName = accountName,
EncryptedPassword = encryptedPassword,
Url = url,
Category = category
};
var passwordEntryBuilder = new PasswordEntryBuilder();
passwordEntryBuilder.SetServiceName(serviceName)
.SetAccountName(accountName)
.SetEncryptedPassword(encryptedPassword)
.SetUrl(url)
.SetCategory(category);

var entry = passwordEntryBuilder.Build();

_passwordEntries.Add(entry);
SavePasswordEntries();
Expand Down
14 changes: 14 additions & 0 deletions src/KeyVaultCli.Domain/Factories/PasswordEntryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ public PasswordEntryBuilder SetEncryptedPassword(string encryptedPassword)
return this;
}

public PasswordEntryBuilder SetUrl(string url)
{
_passwordEntry.Url = url;
_passwordEntry.LastModifiedDate = DateTime.UtcNow;
return this;
}

public PasswordEntryBuilder SetCategory(string category)
{
_passwordEntry.Category = category;
_passwordEntry.LastModifiedDate = DateTime.UtcNow;
return this;
}

public PasswordEntry Build()
{
return _passwordEntry;
Expand Down

0 comments on commit 2b34597

Please sign in to comment.