mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 16:10:16 -04:00
Most services are implemented as command/queries
Code cleanup
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Commands.AddRecent
|
||||
{
|
||||
public class AddRecentCommand: IRequest
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
|
||||
public class AddRecentCommandHandler: IRequestHandler<AddRecentCommand>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
|
||||
public AddRecentCommandHandler(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
}
|
||||
|
||||
public void Handle(AddRecentCommand message)
|
||||
{
|
||||
_recent.Add(new FileInfo
|
||||
{
|
||||
Name = message.Name,
|
||||
Path = message.Path
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Commands.ClearAllRecent
|
||||
{
|
||||
public class ClearAllRecentCommand : IRequest
|
||||
{
|
||||
public class ClearAllRecentCommandHandler : IRequestHandler<ClearAllRecentCommand>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
|
||||
public ClearAllRecentCommandHandler(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
}
|
||||
|
||||
public void Handle(ClearAllRecentCommand message)
|
||||
{
|
||||
_recent.ClearAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
ModernKeePass.Application/Recent/Models/RecentVm.cs
Normal file
18
ModernKeePass.Application/Recent/Models/RecentVm.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Models
|
||||
{
|
||||
public class RecentVm: IMapFrom<FileInfo>
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<FileInfo, RecentVm>()
|
||||
.ForMember(d => d.Name, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Path, opts => opts.MapFrom(s => s.Path));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Recent.Models;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Queries.GetAllRecent
|
||||
{
|
||||
public class GetAllRecentQuery : IRequest<IEnumerable<RecentVm>>
|
||||
{
|
||||
public class GetAllRecentQueryHandler : IAsyncRequestHandler<GetAllRecentQuery, IEnumerable<RecentVm>>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetAllRecentQueryHandler(IRecentProxy recent, IMapper mapper)
|
||||
{
|
||||
_recent = recent;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RecentVm>> Handle(GetAllRecentQuery message)
|
||||
{
|
||||
var fileInfo = await _recent.GetAll();
|
||||
return _mapper.Map<IEnumerable<RecentVm>>(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Recent.Models;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Queries.GetRecent
|
||||
{
|
||||
public class GetRecentQuery : IRequest<RecentVm>
|
||||
{
|
||||
public string Token { get; set; }
|
||||
|
||||
public class GetRecentQueryHandler : IAsyncRequestHandler<GetRecentQuery, RecentVm>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetRecentQueryHandler(IRecentProxy recent, IMapper mapper)
|
||||
{
|
||||
_recent = recent;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<RecentVm> Handle(GetRecentQuery message)
|
||||
{
|
||||
var fileInfo = await _recent.Get(message.Token);
|
||||
return _mapper.Map<RecentVm>(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Queries.HasRecent
|
||||
{
|
||||
public class HasRecentQuery : IRequest<bool>
|
||||
{
|
||||
public class HasRecentQueryHandler : IRequestHandler<HasRecentQuery, bool>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
|
||||
public HasRecentQueryHandler(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
}
|
||||
|
||||
public bool Handle(HasRecentQuery message)
|
||||
{
|
||||
return _recent.EntryCount > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user