using e_suite.API.Common; using e_suite.API.Common.models; using e_suite.Utilities.Pagination; using eSuite.API.security; using eSuite.API.Utilities; using eSuite.Core.MailService; using eSuite.Core.Miscellaneous; using eSuite.Core.Security; using Microsoft.AspNetCore.Mvc; namespace eSuite.API.Controllers; /// /// Mail templates are used when preparing emails that are sent by the system /// [Route("api/[controller]")] public class MailTemplatesController : ESuiteControllerBase { private readonly IMailTemplateManager _mailTemplateManager; /// /// Constructor for MailTemplate controller /// /// public MailTemplatesController(IMailTemplateManager mailTemplateManager) { _mailTemplateManager = mailTemplateManager; } /// /// Retrieve a list of the mail templates /// /// /// /// [Route("types")] [HttpGet] [AccessKey(SecurityAccess.Everyone)] [ProducesResponseType(StatusCodes.Status200OK)] public async Task GetMailTemplateTypes( [FromQuery] Paging paging, CancellationToken cancellationToken = default! ) { var result = await _mailTemplateManager.GetMailTemplateTypes(paging, cancellationToken); return Ok(result); } /// /// Return the details for a given mail template. It will either return the domain specific version of the template, or the master copy as used by Sun. /// /// /// /// /// [Route("template")] [HttpGet] [AccessKey(SecurityAccess.Everyone)] [ProducesResponseType(StatusCodes.Status200OK)] public async Task GetMailTemplate( [FromQuery] GeneralIdRef domain, MailType mailType, CancellationToken cancellationToken = default! ) { var result = await _mailTemplateManager.GetMailTemplate(domain, mailType, cancellationToken); return Ok(result); } /// /// Save a mail template to the system to use by that domain. /// /// /// /// [Route("template")] [HttpPost] [AccessKey(SecurityAccess.Everyone)] [ProducesResponseType(StatusCodes.Status200OK)] public async Task PostMailTemplate( [FromBody] PostMailTemplate mailTemplate, CancellationToken cancellationToken = default! ) { await _mailTemplateManager.PostMailTemplate(mailTemplate, AuditUserDetails, cancellationToken); return Ok(); } }