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:
@@ -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