mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Update groups finally implemented
Code cleanup
This commit is contained in:
@@ -94,6 +94,7 @@
|
||||
<Compile Include="Entry\Queries\GetEntry\GetEntryQuery.cs" />
|
||||
<Compile Include="Group\Commands\DeleteEntry\DeleteEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\DeleteGroup\DeleteGroupCommand.cs" />
|
||||
<Compile Include="Group\Commands\UpdateGroup\UpdateGroupCommand.cs" />
|
||||
<Compile Include="Group\Queries\GetGroup\GetGroupQuery.cs" />
|
||||
<Compile Include="Group\Queries\SearchEntries\SearchEntriesQuery.cs" />
|
||||
<Compile Include="Parameters\Commands\SetCipher\SetCipherCommand.cs" />
|
||||
@@ -136,9 +137,7 @@
|
||||
<Compile Include="Security\Queries\EstimatePasswordComplexity\EstimatePasswordComplexityQuery.cs" />
|
||||
<Content Include="Services\DatabaseService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Group\Commands\UpdateGroup\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ModernKeePass.Domain\Domain.csproj">
|
||||
<Project>{9a0759f1-9069-4841-99e3-3bec44e17356}</Project>
|
||||
|
@@ -34,7 +34,7 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
Task MoveEntry(string parentGroupId, string entryId, int index);
|
||||
Task AddGroup(string parentGroupId, string groupId);
|
||||
void UpdateEntry(string entryId, string fieldName, object fieldValue);
|
||||
void UpdateGroup(string groupId);
|
||||
void UpdateGroup(GroupEntity group);
|
||||
Task RemoveEntry(string parentGroupId, string entryId);
|
||||
Task RemoveGroup(string parentGroupId, string groupId);
|
||||
void DeleteEntity(string entityId);
|
||||
@@ -43,8 +43,8 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
void SortEntries(string groupId);
|
||||
void SortSubGroups(string groupId);
|
||||
|
||||
void AddHistory(string entryId);
|
||||
void RestoreFromHistory(string entryId, int historyIndex);
|
||||
EntryEntity AddHistory(string entryId);
|
||||
EntryEntity RestoreFromHistory(string entryId, int historyIndex);
|
||||
void DeleteHistory(string entryId, int historyIndex);
|
||||
|
||||
IEnumerable<EntryEntity> Search(string groupId, string text);
|
||||
|
@@ -1,27 +1,32 @@
|
||||
using MediatR;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Entry.Commands.AddHistory
|
||||
{
|
||||
public class AddHistoryCommand : IRequest
|
||||
{
|
||||
public string EntryId { get; set; }
|
||||
public EntryVm Entry { get; set; }
|
||||
|
||||
public class AddHistoryCommandHandler : IRequestHandler<AddHistoryCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public AddHistoryCommandHandler(IDatabaseProxy database)
|
||||
public AddHistoryCommandHandler(IDatabaseProxy database, IMapper mapper)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public void Handle(AddHistoryCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
_database.AddHistory(message.EntryId);
|
||||
var history = _database.AddHistory(message.Entry.Id);
|
||||
message.Entry.History.Add(_mapper.Map<EntryVm>(history));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,13 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Entry.Commands.DeleteHistory
|
||||
{
|
||||
public class DeleteHistoryCommand : IRequest
|
||||
{
|
||||
public string EntryId { get; set; }
|
||||
public EntryVm Entry { get; set; }
|
||||
public int HistoryIndex { get; set; }
|
||||
|
||||
public class DeleteHistoryCommandHandler : IRequestHandler<DeleteHistoryCommand>
|
||||
@@ -22,7 +23,8 @@ namespace ModernKeePass.Application.Entry.Commands.DeleteHistory
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
_database.DeleteHistory(message.EntryId, message.HistoryIndex);
|
||||
_database.DeleteHistory(message.Entry.Id, message.HistoryIndex);
|
||||
message.Entry.History.RemoveAt(message.HistoryIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,28 +1,33 @@
|
||||
using MediatR;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Entry.Commands.RestoreHistory
|
||||
{
|
||||
public class RestoreHistoryCommand : IRequest
|
||||
{
|
||||
public string EntryId { get; set; }
|
||||
public EntryVm Entry { get; set; }
|
||||
public int HistoryIndex { get; set; }
|
||||
|
||||
public class RestoreHistoryCommandHandler : IRequestHandler<RestoreHistoryCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public RestoreHistoryCommandHandler(IDatabaseProxy database)
|
||||
public RestoreHistoryCommandHandler(IDatabaseProxy database, IMapper mapper)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public void Handle(RestoreHistoryCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
_database.RestoreFromHistory(message.EntryId, message.HistoryIndex);
|
||||
var entry = _database.RestoreFromHistory(message.Entry.Id, message.HistoryIndex);
|
||||
message.Entry = _mapper.Map<EntryVm>(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ namespace ModernKeePass.Application.Entry.Models
|
||||
public string Notes { get; set; }
|
||||
public Uri Url { get; set; }
|
||||
public Dictionary<string, string> AdditionalFields { get; set; }
|
||||
public IEnumerable<EntryVm> History { get; set; }
|
||||
public List<EntryVm> History { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public Color ForegroundColor { get; set; }
|
||||
public Color BackgroundColor { get; set; }
|
||||
|
@@ -0,0 +1,41 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Group.Commands.UpdateGroup
|
||||
{
|
||||
public class UpdateGroupCommand : IRequest
|
||||
{
|
||||
public GroupVm Group { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
|
||||
public class UpdateGroupCommandHandler : IRequestHandler<UpdateGroupCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public UpdateGroupCommandHandler(IDatabaseProxy database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public void Handle(UpdateGroupCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
var group = new GroupEntity
|
||||
{
|
||||
Id = message.Group.Id,
|
||||
Name = message.Title,
|
||||
Icon = message.Icon
|
||||
};
|
||||
_database.UpdateGroup(group);
|
||||
message.Group.Title = message.Title;
|
||||
message.Group.Icon = message.Icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user