Add ISender extension methods for reading email templates
Introduced ReadEmailTemplateQueryExtensions with methods to fetch a single EmailTemplateDto by ID or type and language code. Added required using directive for EnvelopeGenerator.Application.Common.Extensions. These extensions streamline querying email templates via ISender.
This commit is contained in:
@@ -6,6 +6,7 @@ using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EnvelopeGenerator.Domain.Constants;
|
||||
using DigitalData.Core.Exceptions;
|
||||
using EnvelopeGenerator.Application.Common.Extensions;
|
||||
|
||||
namespace EnvelopeGenerator.Application.EmailTemplates.Queries;
|
||||
|
||||
@@ -41,6 +42,40 @@ public record ReadEmailTemplateQuery : IEmailTemplateQuery, IRequest<IEnumerable
|
||||
public string? LangCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class ReadEmailTemplateQueryExtensions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="langCode"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<EmailTemplateDto?> ReadEmailTemplateById(this ISender sender, int id, string langCode, CancellationToken cancel = default)
|
||||
{
|
||||
var result = await sender.Send(new ReadEmailTemplateQuery { Id = id, LangCode = langCode }, cancel);
|
||||
return result.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="langCode"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<EmailTemplateDto?> ReadEmailTemplateByType(this ISender sender, EmailTemplateType type, string langCode, CancellationToken cancel = default)
|
||||
{
|
||||
var result = await sender.Send(new ReadEmailTemplateQuery { Type = type, LangCode = langCode }, cancel);
|
||||
return result.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user