Renamed service

This commit is contained in:
TypoMustakes
2025-10-28 12:28:22 +01:00
parent 667f624229
commit 118aa459bb
7 changed files with 23 additions and 17 deletions

View File

@@ -15,7 +15,7 @@ class Program
var application = Adw.Application.New("org.typomustakes.keychain", Gio.ApplicationFlags.FlagsNone);
application.OnActivate += (sender, args) =>
{
var passwordStoreService = provider.GetRequiredService<IPasswordStoreService>();
var passwordStoreService = provider.GetRequiredService<ICollectionsService>();
var window = new UI.MainWindow(passwordStoreService).Window;
window.Application = (Adw.Application)sender;
window.Show();
@@ -27,7 +27,7 @@ class Program
private static ServiceProvider SetupServices()
{
var services = new ServiceCollection();
services.AddSingleton<IPasswordStoreService, PasswordStoreService>();
services.AddSingleton<ICollectionsService, CollectionsService>();
services.AddSingleton<IBookmarksRepository, BookmarksRepository>();
services.AddSingleton<ISecretService, SecretService>();
return services.BuildServiceProvider();

View File

@@ -19,7 +19,7 @@ public partial class MainWindow
private const string searchEntryId = "search_entry";
private const string passwordListId = "password_list";
public MainWindow(IPasswordStoreService passwordStoreService)
public MainWindow(ICollectionsService passwordStoreService)
{
this.passwordStoreService = passwordStoreService;

View File

@@ -7,7 +7,7 @@ namespace Keychain.UI;
public partial class MainWindow
{
private const string DEFAULT_SHORTCUT_NAME = "Keychain";
private readonly IPasswordStoreService passwordStoreService;
private readonly ICollectionsService passwordStoreService;
private PreferencesGroup shortcutsGroup;
private BookmarkCollection shortcuts;

View File

@@ -8,12 +8,12 @@ using System.Collections.Specialized;
public class BookmarkCollection : ObservableCollection<BookmarkViewModel>
{
private readonly IPasswordStoreService _passwordStoreService;
private readonly ICollectionsService _passwordStoreService;
private readonly PreferencesGroup shortcutsGroup;
private Dictionary<BookmarkViewModel, ActionRow> itemToRowMap = new();
public BookmarkCollection(PreferencesGroup shortcutsGroup, IPasswordStoreService passwordStoreService)
public BookmarkCollection(PreferencesGroup shortcutsGroup, ICollectionsService passwordStoreService)
: base()
{
this.shortcutsGroup = shortcutsGroup;
@@ -94,7 +94,9 @@ public class BookmarkCollection : ObservableCollection<BookmarkViewModel>
public void Add(string path, string? displayName = null)
{
BookmarkViewModel item = new BookmarkViewModel(path, displayName);
if (_passwordStoreService.Create(item.Model))
{
Add(item);
_passwordStoreService.Create(item.Model);
}
}
}

View File

@@ -8,11 +8,11 @@ namespace Keychain.ViewModels;
public class PasswordList : ObservableCollection<PasswordViewModel>
{
private readonly IPasswordStoreService _passwordService;
private readonly ICollectionsService _passwordService;
private readonly PreferencesGroup list;
private Dictionary<PasswordViewModel, ActionRow> itemToRowMap = new();
public PasswordList(PreferencesGroup list, IPasswordStoreService passwordService)
public PasswordList(PreferencesGroup list, ICollectionsService passwordService)
: base()
{
this.list = list;

View File

@@ -3,21 +3,25 @@ using Repository;
namespace Logic;
public class PasswordStoreService : IPasswordStoreService
public class CollectionsService : ICollectionsService
{
private readonly IBookmarksRepository repository;
private readonly ISecretService secretService;
public PasswordStoreService(IBookmarksRepository repository, ISecretService secretService)
public CollectionsService(IBookmarksRepository repository, ISecretService secretService)
{
this.repository = repository;
this.secretService = secretService;
}
public void Create(PasswordStore item)
public bool Create(PasswordStore item)
{
if (secretService.CreateCollection(item.DisplayName ?? item.Path))
{
secretService.CreateCollection(item.DisplayName ?? item.Path);
repository.Create(item);
return true;
}
return false;
}
public void Delete(uint ID)

View File

@@ -2,12 +2,12 @@ using Models;
namespace Logic;
public interface IPasswordStoreService
public interface ICollectionsService
{
IEnumerable<PasswordStore> GetAll();
PasswordStore Get(uint ID);
void Delete(uint ID);
void Delete(PasswordStore item);
void Create(PasswordStore item);
bool Create(PasswordStore item);
void Edit(uint ID, PasswordStore newItem);
}