Most services are implemented as command/queries

Code cleanup
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-26 19:04:51 +01:00
parent 903e7649e4
commit 22072bb2fe
46 changed files with 567 additions and 390 deletions

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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;
}
}
}
}