- Introduced `CountHistoryQuery` record for querying the count of history entries of an envelope. - Implemented `CountHistoryQueryHandler` using repository pattern and AutoMapper. - Supports optional filtering by `Status`. - Throws `NotFoundException` if necessary (placeholder for future extension).
54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using AutoMapper;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
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 Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnvelopeGenerator.Application.Histories.Queries;
|
|
|
|
//TODO: Add sender query
|
|
/// <summary>
|
|
/// Repräsentiert eine Abfrage für die Verlaufshistorie eines Umschlags.
|
|
/// </summary>
|
|
public record CountHistoryQuery : HistoryQueryBase, IRequest<int>;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class CountHistoryQueryHandler : IRequestHandler<CountHistoryQuery, int>
|
|
{
|
|
private readonly IRepository<History> _repo;
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repo"></param>
|
|
/// <param name="mapper"></param>
|
|
public CountHistoryQueryHandler(IRepository<History> repo, IMapper mapper)
|
|
{
|
|
_repo = repo;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotFoundException"></exception>
|
|
public Task<int> Handle(CountHistoryQuery request, CancellationToken cancel = default)
|
|
{
|
|
var query = _repo.Where(h => h.EnvelopeId == request.EnvelopeId);
|
|
if (request.Status is not null)
|
|
query = query.Where(h => h.Status == request.Status);
|
|
|
|
return query.CountAsync(cancel);
|
|
}
|
|
} |