feat: implement ReadEnvelopeReportQuery with handler and repository integration
- Add ReadEnvelopeReportQuery record that returns IEnumerable<EnvelopeReport> - Implement ReadEnvelopeReportQueryHandler with repository and AutoMapper integration - Add ThrowIfNotFound property with JsonIgnore and NotMapped attributes - Integrate IRepository<EnvelopeReport> for data access - Add NotFoundException when no reports found and ThrowIfNotFound is true - Configure Entity Framework Core using Microsoft.EntityFrameworkCore - Add JSON serialization configuration with System.Text.Json - Update using statements with necessary abstractions and exceptions
This commit is contained in:
parent
972c63388e
commit
8459706c45
@ -1,9 +1,15 @@
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using AutoMapper;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using DigitalData.Core.Exceptions;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EnvelopeGenerator.Application.EnvelopeReports;
|
||||
@ -11,4 +17,56 @@ namespace EnvelopeGenerator.Application.EnvelopeReports;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public record ReadEnvelopeReportQuery(int EnvelopeId) : IRequest;
|
||||
public record ReadEnvelopeReportQuery(int EnvelopeId) : IRequest<IEnumerable<EnvelopeReport>>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public bool ThrowIfNotFound { get; init; } = true;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ReadEnvelopeReportQueryHandler : IRequestHandler<ReadEnvelopeReportQuery, IEnumerable<EnvelopeReport>>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private readonly IRepository<EnvelopeReport> _repo;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
/// <param name="mapper"></param>
|
||||
public ReadEnvelopeReportQueryHandler(IRepository<EnvelopeReport> repo, IMapper mapper)
|
||||
{
|
||||
_repo = repo;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<EnvelopeReport>> Handle(ReadEnvelopeReportQuery request, CancellationToken cancel = default)
|
||||
{
|
||||
var reports = await _repo.Where(r => r.EnvelopeId == request.EnvelopeId).ToListAsync(cancel);
|
||||
var reportDtos = _mapper.Map<IEnumerable<EnvelopeReport>>(reports);
|
||||
|
||||
if(request.ThrowIfNotFound && !reportDtos.Any())
|
||||
throw new NotFoundException($"EnvelopeReport with EnvelopeId '{request.EnvelopeId}' was not found.");
|
||||
|
||||
return reportDtos;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user