Refactored the EmailTemplateQuery record to EmailTemplateQueryBase across the codebase. Updated all references, method signatures, inheritance, and documentation to use the new base type. No functional changes; this improves clarity and generalization for email template queries.
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using AutoMapper;
|
|
using MediatR;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnvelopeGenerator.Application.EmailTemplates.Queries.Read;
|
|
|
|
/// <summary>
|
|
/// Stellt eine Abfrage dar, um eine E-Mail-Vorlage zu lesen.
|
|
/// Diese Klasse erbt von <see cref="EmailTemplateQueryBase"/>.
|
|
/// </summary>
|
|
public record ReadEmailTemplateQuery : EmailTemplateQueryBase, IRequest<EmailTemplateDto?>
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ReadEmailTemplateQueryHandler : IRequestHandler<ReadEmailTemplateQuery, EmailTemplateDto?>
|
|
{
|
|
private readonly IMapper _mapper;
|
|
|
|
private readonly IRepository<EmailTemplate> _repo;
|
|
|
|
/// <summary>
|
|
/// Initialisiert eine neue Instanz der <see cref="EmailTemplateController"/>-Klasse.
|
|
/// </summary>
|
|
/// <param name="mapper">
|
|
/// <param name="repo">
|
|
/// Die AutoMapper-Instanz, die zum Zuordnen von Objekten verwendet wird.
|
|
/// </param>
|
|
public ReadEmailTemplateQueryHandler(IMapper mapper, IRepository<EmailTemplate> repo)
|
|
{
|
|
_mapper = mapper;
|
|
_repo = repo;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="InvalidOperationException"></exception>
|
|
public async Task<EmailTemplateDto?> Handle(ReadEmailTemplateQuery request, CancellationToken cancel)
|
|
{
|
|
var query = request.Id is int id
|
|
? _repo.Query.Where(temp => temp.Id == id)
|
|
: _repo.Query.Where(temp => temp.Name == request.Type!.ToString());
|
|
|
|
return _mapper.Map<EmailTemplateDto>(await query.FirstOrDefaultAsync(cancel));
|
|
}
|
|
} |