Skip to content

Commit

Permalink
Interface update
Browse files Browse the repository at this point in the history
  • Loading branch information
Yassin Lokhat committed Jan 10, 2025
1 parent b27ec64 commit 0d09c32
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Core/Interfaces/IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface IDatabase : IDisposable
/// Try to load the current user.
/// </summary>
/// <param name="passkey">The current passkey.</param>
/// <returns></returns>
/// <returns>The loaded user.</returns>
IUser? Login(string passkey);

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions Core/Interfaces/IService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ public interface IService : IItem
/// <param name="label">The label of the account.</param>
/// <param name="identifiants">The identifiants.</param>
/// <param name="password">The password.</param>
void AddAccount(string label, IEnumerable<string> identifiants, string password);
/// <returns>The created account.</returns>
IAccount AddAccount(string label, IEnumerable<string> identifiants, string password);

/// <summary>
/// Delete the given account from this service.
/// </summary>
/// <param name="accountId">The Id of the account to delete.</param>
void DeleteAccount(string accountId);
/// <param name="account">The account to delete.</param>
void DeleteAccount(IAccount account);
}
}
7 changes: 4 additions & 3 deletions Core/Interfaces/IUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public interface IUser : IItem
/// Add a new service to the user's services.
/// </summary>
/// <param name="serviceName">The name of the new service.</param>
void AddService(string serviceName);
/// <returns>The created service.</returns>
IService AddService(string serviceName);

/// <summary>
/// Delete the given service from the user's services.
/// </summary>
/// <param name="serviceId">The Id of the service to delete.</param>
void DeleteService(string serviceId);
/// <param name="service">The service to delete.</param>
void DeleteService(IService service);
}
}
13 changes: 8 additions & 5 deletions Core/Models/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ string IService.Notes
set => Notes = Database.AutoSave.UpdateValue(ItemId, nameof(Notes), value);
}

void IService.AddAccount(string label, IEnumerable<string> identifiants, string password)
IAccount IService.AddAccount(string label, IEnumerable<string> identifiants, string password)
{
Account account = new()
{
Expand All @@ -42,14 +42,17 @@ void IService.AddAccount(string label, IEnumerable<string> identifiants, string
};

Accounts.Add(Database.AutoSave.AddValue(ItemId, account));

return account;
}

void IService.DeleteAccount(string accountId)
void IService.DeleteAccount(IAccount account)
{
Account account = Accounts.FirstOrDefault(x => x.ItemId == accountId)
?? throw new KeyNotFoundException($"The '{accountId}' account was not found into the '{ItemId}' service");
Account accountToRemove = Accounts.FirstOrDefault(x => x.ItemId == account.ItemId)
?? throw new KeyNotFoundException($"The '{account.ItemId}' account was not found into the '{ItemId}' service");

_ = Accounts.Remove(Database.AutoSave.DeleteValue(ItemId, accountToRemove));

_ = Accounts.Remove(Database.AutoSave.DeleteValue(ItemId, account));
}

#endregion
Expand Down
12 changes: 7 additions & 5 deletions Core/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int IUser.CleaningClipboardTimeout
set => CleaningClipboardTimeout = Database.AutoSave.UpdateValue(ItemId, nameof(CleaningClipboardTimeout), value);
}

void IUser.AddService(string serviceName)
IService IUser.AddService(string serviceName)
{
Service service = new()
{
Expand All @@ -45,14 +45,16 @@ void IUser.AddService(string serviceName)
};

Services.Add(Database.AutoSave.AddValue(ItemId, service));

return service;
}

void IUser.DeleteService(string serviceId)
void IUser.DeleteService(IService service)
{
Service service = Services.FirstOrDefault(x => x.ItemId == serviceId)
?? throw new KeyNotFoundException($"The '{serviceId}' service was not found into the '{ItemId}' user");
Service serviceToRemove = Services.FirstOrDefault(x => x.ItemId == service.ItemId)
?? throw new KeyNotFoundException($"The '{service.ItemId}' service was not found into the '{ItemId}' user");

_ = Services.Remove(Database.AutoSave.DeleteValue(ItemId, service));
_ = Services.Remove(Database.AutoSave.DeleteValue(ItemId, serviceToRemove));
}

#endregion
Expand Down

0 comments on commit 0d09c32

Please sign in to comment.