mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
WIP change to ids
This commit is contained in:
@@ -51,6 +51,8 @@
|
||||
<Compile Include="Common\Interfaces\ISettingsProxy.cs" />
|
||||
<Compile Include="Common\Mappings\IMapFrom.cs" />
|
||||
<Compile Include="Common\Mappings\MappingProfile.cs" />
|
||||
<Compile Include="Entry\Queries\GetEntry\GetEntryQuery.cs" />
|
||||
<Compile Include="Group\Queries\GetGroup\GetGroupQuery.cs" />
|
||||
<Compile Include="Parameters\Commands\SetCipher\SetCipherCommand.cs" />
|
||||
<Compile Include="Parameters\Commands\SetCompression\SetCompressionCommand.cs" />
|
||||
<Compile Include="Parameters\Commands\SetHasRecycleBin\SetHasRecycleBinCommand.cs" />
|
||||
@@ -79,8 +81,6 @@
|
||||
<Compile Include="Group\Commands\AddGroup\AddGroupCommand.cs" />
|
||||
<Compile Include="Group\Commands\CreateEntry\CreateEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\CreateGroup\CreateGroupCommand.cs" />
|
||||
<Compile Include="Group\Commands\DeleteEntry\DeleteEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\DeleteGroup\DeleteGroupCommand.cs" />
|
||||
<Compile Include="Group\Commands\InsertEntry\InsertEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\RemoveEntry\RemoveEntryCommand.cs" />
|
||||
<Compile Include="Group\Commands\RemoveGroup\RemoveGroupCommand.cs" />
|
||||
@@ -94,9 +94,7 @@
|
||||
<Content Include="Services\DatabaseService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Entry\Queries\GetEntry\" />
|
||||
<Folder Include="Group\Commands\UpdateGroup\" />
|
||||
<Folder Include="Group\Queries\GetGroup\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ModernKeePass.Domain\Domain.csproj">
|
||||
|
@@ -9,17 +9,16 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
bool IsOpen { get; }
|
||||
string Name { get; }
|
||||
GroupEntity RootGroup { get; }
|
||||
|
||||
GroupEntity RecycleBin { get; set; }
|
||||
string RootGroupId { get; }
|
||||
string RecycleBinId { get; set; }
|
||||
string CipherId { get; set; }
|
||||
string KeyDerivationId { get; set; }
|
||||
string Compression { get; set; }
|
||||
bool IsRecycleBinEnabled { get; set; }
|
||||
|
||||
Task<GroupEntity> Open(FileInfo fileInfo, Credentials credentials);
|
||||
Task<GroupEntity> ReOpen();
|
||||
Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2);
|
||||
Task Open(FileInfo fileInfo, Credentials credentials);
|
||||
Task ReOpen();
|
||||
Task Create(FileInfo fileInfo, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2);
|
||||
Task SaveDatabase();
|
||||
Task SaveDatabase(string filePath);
|
||||
void SetRecycleBin(string id);
|
||||
@@ -31,14 +30,13 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
Task AddGroup(string parentGroupId, string groupId);
|
||||
void UpdateEntry(string entryId, string fieldName, object fieldValue);
|
||||
void UpdateGroup(string groupId);
|
||||
Task RemoveEntry(string parentGroupId, string entryId);
|
||||
Task RemoveGroup(string parentGroupId, string groupId);
|
||||
Task RemoveEntry(string parentGroupId, string entryId, bool isToBeDeleted);
|
||||
Task RemoveGroup(string parentGroupId, string groupId, bool isToBeDeleted);
|
||||
EntryEntity CreateEntry(string parentGroupId);
|
||||
GroupEntity CreateGroup(string parentGroupId, string nameId, bool isRecycleBin = false);
|
||||
Task DeleteEntry(string entryId);
|
||||
Task DeleteGroup(string groupId);
|
||||
|
||||
void SortEntries(string groupId);
|
||||
void SortSubGroups(string groupId);
|
||||
EntryEntity GetEntry(string id);
|
||||
GroupEntity GetGroup(string id);
|
||||
}
|
||||
}
|
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
@@ -9,7 +8,7 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
string Id { get; set; }
|
||||
string Title { get; set; }
|
||||
Icon Icon { get; set; }
|
||||
List<GroupVm> Breadcrumb { get; }
|
||||
GroupVm ParentGroup { get; set; }
|
||||
List<IEntityVm> Breadcrumb { get; }
|
||||
string ParentGroupId { get; set; }
|
||||
}
|
||||
}
|
@@ -1,35 +1,31 @@
|
||||
using MediatR;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
{
|
||||
public class CreateDatabaseCommand : IRequest<GroupVm>
|
||||
public class CreateDatabaseCommand : IRequest
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string KeyFilePath { get; set; }
|
||||
|
||||
public class CreateDatabaseCommandHandler : IAsyncRequestHandler<CreateDatabaseCommand, GroupVm>
|
||||
public class CreateDatabaseCommandHandler : IAsyncRequestHandler<CreateDatabaseCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CreateDatabaseCommandHandler(IDatabaseProxy database, IMapper mapper)
|
||||
public CreateDatabaseCommandHandler(IDatabaseProxy database)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<GroupVm> Handle(CreateDatabaseCommand message)
|
||||
public async Task Handle(CreateDatabaseCommand message)
|
||||
{
|
||||
if (_database.IsOpen) throw new DatabaseOpenException();
|
||||
|
||||
var rootGroup = await _database.Create(
|
||||
await _database.Create(
|
||||
new FileInfo
|
||||
{
|
||||
Path = message.FilePath
|
||||
@@ -39,7 +35,6 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
KeyFilePath = message.KeyFilePath,
|
||||
Password = message.Password
|
||||
});
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@ namespace ModernKeePass.Application.Database.Models
|
||||
{
|
||||
public bool IsOpen { get; set; }
|
||||
public string Name { get; set; }
|
||||
public GroupVm RootGroup { get; set; }
|
||||
public GroupVm RecycleBin { get; set; }
|
||||
public string RootGroupId { get; set; }
|
||||
public string RecycleBinId { get; set; }
|
||||
public bool IsRecycleBinEnabled { get; set; }
|
||||
public string Compression { get; set; }
|
||||
public string CipherId { get; set; }
|
||||
|
@@ -28,9 +28,9 @@ namespace ModernKeePass.Application.Database.Queries.GetDatabase
|
||||
if (database.IsOpen)
|
||||
{
|
||||
database.Name = _databaseProxy.Name;
|
||||
database.RootGroup = GroupVm.BuildHierarchy(null, _databaseProxy.RootGroup, _mapper);
|
||||
database.RootGroupId = _databaseProxy.RootGroupId;
|
||||
database.IsRecycleBinEnabled = _databaseProxy.IsRecycleBinEnabled;
|
||||
database.RecycleBin = _mapper.Map<GroupVm>(_databaseProxy.RecycleBin);
|
||||
database.RecycleBinId = _databaseProxy.RecycleBinId;
|
||||
database.Compression = _databaseProxy.Compression;
|
||||
database.CipherId = _databaseProxy.CipherId;
|
||||
database.KeyDerivationId = _databaseProxy.CipherId;
|
||||
|
@@ -1,38 +1,31 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
{
|
||||
public class OpenDatabaseQuery: IRequest<GroupVm>
|
||||
public class OpenDatabaseQuery: IRequest
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string KeyFilePath { get; set; }
|
||||
|
||||
public class OpenDatabaseQueryHandler : IAsyncRequestHandler<OpenDatabaseQuery, GroupVm>
|
||||
public class OpenDatabaseQueryHandler : IAsyncRequestHandler<OpenDatabaseQuery>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public OpenDatabaseQueryHandler(IMapper mapper, IDatabaseProxy database)
|
||||
public OpenDatabaseQueryHandler(IDatabaseProxy database)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task<GroupVm> Handle(OpenDatabaseQuery request)
|
||||
public async Task Handle(OpenDatabaseQuery request)
|
||||
{
|
||||
if (_database.IsOpen) throw new DatabaseOpenException();
|
||||
|
||||
var rootGroup = await _database.Open(
|
||||
await _database.Open(
|
||||
new FileInfo
|
||||
{
|
||||
Path = request.FilePath
|
||||
@@ -42,7 +35,6 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
KeyFilePath = request.KeyFilePath,
|
||||
Password = request.Password
|
||||
});
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,31 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Queries.ReOpenDatabase
|
||||
{
|
||||
public class ReOpenDatabaseQuery: IRequest<GroupVm>
|
||||
public class ReOpenDatabaseQuery: IRequest
|
||||
{
|
||||
public class ReOpenDatabaseQueryHandler : IAsyncRequestHandler<ReOpenDatabaseQuery, GroupVm>
|
||||
public class ReOpenDatabaseQueryHandler : IAsyncRequestHandler<ReOpenDatabaseQuery>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public ReOpenDatabaseQueryHandler(IMapper mapper, IDatabaseProxy database)
|
||||
public ReOpenDatabaseQueryHandler(IDatabaseProxy database)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task<GroupVm> Handle(ReOpenDatabaseQuery request)
|
||||
public async Task Handle(ReOpenDatabaseQuery request)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
var rootGroup = await _database.ReOpen();
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
await _database.ReOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ using System.Drawing;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
@@ -12,8 +11,8 @@ namespace ModernKeePass.Application.Entry.Models
|
||||
{
|
||||
public class EntryVm: IEntityVm, IMapFrom<EntryEntity>
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public List<GroupVm> Breadcrumb { get; } = new List<GroupVm>();
|
||||
public string ParentGroupId { get; set; }
|
||||
public List<IEntityVm> Breadcrumb { get; } = new List<IEntityVm>();
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Username { get; set; }
|
||||
@@ -37,7 +36,7 @@ namespace ModernKeePass.Application.Entry.Models
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<EntryEntity, EntryVm>()
|
||||
.ForMember(d => d.ParentGroup, opts => opts.Ignore())
|
||||
.ForMember(d => d.ParentGroupId, opts => opts.MapFrom(s => s.ParentId))
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
|
||||
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Username, opts => opts.MapFrom(s => s.UserName))
|
||||
|
@@ -0,0 +1,31 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Entry.Queries.GetEntry
|
||||
{
|
||||
public class GetEntryQuery: IRequest<EntryVm>
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public class GetEntryQueryHandler: IRequestHandler<GetEntryQuery, EntryVm>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetEntryQueryHandler(IDatabaseProxy database, IMapper mapper)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public EntryVm Handle(GetEntryQuery message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
return _mapper.Map<EntryVm>(_database.GetEntry(message.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,7 +8,7 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
|
||||
{
|
||||
public class CreateGroupCommand : IRequest<GroupVm>
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public string ParentGroupId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsRecycleBin { get; set; }
|
||||
|
||||
@@ -27,10 +27,8 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
var group = _database.CreateGroup(message.ParentGroup.Id, message.Name, message.IsRecycleBin);
|
||||
var group = _database.CreateGroup(message.ParentGroupId, message.Name, message.IsRecycleBin);
|
||||
var groupVm = _mapper.Map<GroupVm>(group);
|
||||
groupVm.ParentGroup = message.ParentGroup;
|
||||
message.ParentGroup.SubGroups.Add(groupVm);
|
||||
return groupVm;
|
||||
}
|
||||
}
|
||||
|
@@ -1,31 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Group.Commands.DeleteEntry
|
||||
{
|
||||
public class DeleteEntryCommand : IRequest
|
||||
{
|
||||
public EntryVm Entry { get; set; }
|
||||
|
||||
public class DeleteEntryCommandHandler : IAsyncRequestHandler<DeleteEntryCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public DeleteEntryCommandHandler(IDatabaseProxy database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task Handle(DeleteEntryCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
await _database.DeleteEntry(message.Entry.Id);
|
||||
message.Entry = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Group.Commands.DeleteGroup
|
||||
{
|
||||
public class DeleteGroupCommand : IRequest
|
||||
{
|
||||
public GroupVm Group { get; set; }
|
||||
|
||||
public class DeleteGroupCommandHandler : IAsyncRequestHandler<DeleteGroupCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
|
||||
public DeleteGroupCommandHandler(IDatabaseProxy database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public async Task Handle(DeleteGroupCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
await _database.DeleteGroup(message.Group.Id);
|
||||
message.Group = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,6 +11,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveEntry
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public EntryVm Entry { get; set; }
|
||||
public bool IsDelete { get; set; }
|
||||
|
||||
public class RemoveEntryCommandHandler : IAsyncRequestHandler<RemoveEntryCommand>
|
||||
{
|
||||
@@ -25,7 +26,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveEntry
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id);
|
||||
await _database.RemoveEntry(message.ParentGroup.Id, message.Entry.Id, message.IsDelete);
|
||||
message.ParentGroup.Entries.Remove(message.Entry);
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveGroup
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public GroupVm Group { get; set; }
|
||||
public bool IsDelete { get; set; }
|
||||
|
||||
public class RemoveGroupCommandHandler : IAsyncRequestHandler<RemoveGroupCommand>
|
||||
{
|
||||
@@ -24,7 +25,7 @@ namespace ModernKeePass.Application.Group.Commands.RemoveGroup
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id);
|
||||
await _database.RemoveGroup(message.ParentGroup.Id, message.Group.Id, message.IsDelete);
|
||||
message.ParentGroup.SubGroups.Remove(message.Group);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
@@ -13,11 +11,11 @@ namespace ModernKeePass.Application.Group.Models
|
||||
{
|
||||
public class GroupVm: IEntityVm, ISelectableModel, IMapFrom<GroupEntity>
|
||||
{
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public string ParentGroupId { get; set; }
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public List<GroupVm> Breadcrumb { get; } = new List<GroupVm>();
|
||||
public List<IEntityVm> Breadcrumb { get; } = new List<IEntityVm>();
|
||||
public List<GroupVm> SubGroups { get; set; }
|
||||
public List<EntryVm> Entries { get; set; }
|
||||
public bool IsSelected { get; set; }
|
||||
@@ -30,34 +28,13 @@ namespace ModernKeePass.Application.Group.Models
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<GroupEntity, GroupVm>()
|
||||
.ForMember(d => d.ParentGroup, opts => opts.Ignore())
|
||||
.ForMember(d => d.ParentGroupId, opts => opts.MapFrom(s => s.ParentId))
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
|
||||
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Icon, opts => opts.MapFrom(s => s.Icon))
|
||||
.ForMember(d => d.Entries, opts => opts.Ignore())
|
||||
.ForMember(d => d.SubGroups, opts => opts.Ignore());
|
||||
}
|
||||
|
||||
internal static GroupVm BuildHierarchy(GroupVm parentGroup, GroupEntity groupEntity, IMapper mapper)
|
||||
{
|
||||
var groupVm = mapper.Map<GroupVm>(groupEntity);
|
||||
groupVm.ParentGroup = parentGroup;
|
||||
if (parentGroup != null)
|
||||
{
|
||||
groupVm.Breadcrumb.AddRange(parentGroup.Breadcrumb);
|
||||
groupVm.Breadcrumb.Add(parentGroup);
|
||||
}
|
||||
groupVm.Entries = groupEntity.Entries.Select(e =>
|
||||
{
|
||||
var entry = mapper.Map<EntryVm>(e);
|
||||
entry.ParentGroup = groupVm;
|
||||
entry.Breadcrumb.AddRange(groupVm.Breadcrumb);
|
||||
entry.Breadcrumb.Add(groupVm);
|
||||
return entry;
|
||||
}).OrderBy(e => e.Title).ToList();
|
||||
groupVm.SubGroups = groupEntity.SubGroups.Select(g => BuildHierarchy(groupVm, g, mapper)).ToList();
|
||||
|
||||
return groupVm;
|
||||
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries))
|
||||
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.SubGroups))
|
||||
.MaxDepth(1);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Group.Queries.GetGroup
|
||||
{
|
||||
public class GetGroupQuery : IRequest<GroupVm>
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public class GetGroupQueryHandler : IRequestHandler<GetGroupQuery, GroupVm>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetGroupQueryHandler(IDatabaseProxy database, IMapper mapper)
|
||||
{
|
||||
_database = database;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public GroupVm Handle(GetGroupQuery message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
return _mapper.Map<GroupVm>(_database.GetGroup(message.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user