Simplified Repository, Logic handles more by itself

This commit is contained in:
2025-09-30 10:41:12 +02:00
parent 7ac87ea568
commit c8c24cb7cc
3 changed files with 9 additions and 65 deletions

View File

@@ -69,24 +69,6 @@ public class JsonRepository : IRepository, IDisposable
return _cache;
}
public PasswordStore? Get(uint id)
{
try
{
return _cache.First(item => item.ID.Equals(id));
}
catch (InvalidOperationException)
{
// Not found
return null;
}
catch (Exception e)
{
WriteToStdErr($"Unexpected error: {e.Message}");
return null;
}
}
public void Dispose()
{
if (_cacheAhead)
@@ -114,26 +96,6 @@ public class JsonRepository : IRepository, IDisposable
}
}
public void Edit(uint ID, PasswordStore newItem)
{
try
{
PasswordStore item = _cache.First(item => item.ID.Equals(ID));
item.DisplayName = newItem.DisplayName;
item.IconName = newItem.IconName;
item.Path = newItem.Path;
_cacheAhead = true;
}
catch (InvalidOperationException)
{
WriteToStdErr($"Edit error: Item with ID {ID} not found.");
}
catch (Exception e)
{
WriteToStdErr($"Unexpected error: {e.Message}");
}
}
public void Create(PasswordStore item)
{
item.ID = ++_autoIncrementedId;
@@ -141,27 +103,10 @@ public class JsonRepository : IRepository, IDisposable
_cacheAhead = true;
}
public void Delete(PasswordStore item)
{
Delete(item.ID);
}
public void Delete(uint id)
{
try
{
var item = _cache.First(item => item.ID.Equals(id));
_cache.Remove(item);
_cacheAhead = true;
}
catch (InvalidOperationException)
{
WriteToStdErr($"Delete error: Item with ID {id} not found.");
}
catch (Exception e)
{
WriteToStdErr($"Unexpected error: {e.Message}");
}
_cache.RemoveAll(i => i.ID == id);
_cacheAhead = true;
}
private void WriteToStdErr(string message)