refactor(history): introduce extension method and remove AutoMapper dependency
- Added `CountHistoryQueryExtensions.AnyHistoryAsync` for cleaner query usage via `ISender`. - Removed `IMapper` from `CountHistoryQueryHandler` as it was unused. - Removed unnecessary `using` directives to simplify imports. - Kept query handling logic intact.
This commit is contained in:
parent
3b24755c35
commit
629b02863b
@ -1,11 +1,7 @@
|
|||||||
using AutoMapper;
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
using DigitalData.Core.Abstraction.Application.Repository;
|
|
||||||
using DigitalData.Core.Exceptions;
|
using DigitalData.Core.Exceptions;
|
||||||
using EnvelopeGenerator.Application.Common.Dto.History;
|
|
||||||
using EnvelopeGenerator.Domain.Constants;
|
|
||||||
using MediatR;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using EnvelopeGenerator.Domain.Entities;
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
|
using MediatR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Histories.Queries;
|
namespace EnvelopeGenerator.Application.Histories.Queries;
|
||||||
@ -16,6 +12,27 @@ namespace EnvelopeGenerator.Application.Histories.Queries;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public record CountHistoryQuery : HistoryQueryBase, IRequest<int>;
|
public record CountHistoryQuery : HistoryQueryBase, IRequest<int>;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class CountHistoryQueryExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="queryOptions"></param>
|
||||||
|
/// <param name="cancel"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<bool> AnyHistoryAsync(this ISender sender, Action<CountHistoryQuery> queryOptions, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
var query = new CountHistoryQuery();
|
||||||
|
queryOptions(query);
|
||||||
|
var count = await sender.Send(query, cancel);
|
||||||
|
return count > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -23,17 +40,13 @@ public class CountHistoryQueryHandler : IRequestHandler<CountHistoryQuery, int>
|
|||||||
{
|
{
|
||||||
private readonly IRepository<History> _repo;
|
private readonly IRepository<History> _repo;
|
||||||
|
|
||||||
private readonly IMapper _mapper;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repo"></param>
|
/// <param name="repo"></param>
|
||||||
/// <param name="mapper"></param>
|
public CountHistoryQueryHandler(IRepository<History> repo)
|
||||||
public CountHistoryQueryHandler(IRepository<History> repo, IMapper mapper)
|
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
_mapper = mapper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -13,10 +13,10 @@ public record HistoryQueryBase
|
|||||||
/// Die eindeutige Kennung des Umschlags.
|
/// Die eindeutige Kennung des Umschlags.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required]
|
[Required]
|
||||||
public int EnvelopeId { get; init; }
|
public int EnvelopeId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Der Include des Umschlags, der abgefragt werden soll. Kann optional angegeben werden, um die Ergebnisse zu filtern.
|
/// Der Include des Umschlags, der abgefragt werden soll. Kann optional angegeben werden, um die Ergebnisse zu filtern.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EnvelopeStatus? Status { get; init; }
|
public EnvelopeStatus? Status { get; set; }
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user