refactor: move REST API controllers into Controllers/Api subfolder
- Prepares Controllers/ for both Api/ and Admin/ groupings - Namespaces updated accordingly Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
using HrynCo.NotificationService.DAL.Abstract.Templates;
|
||||
|
||||
namespace HrynCo.NotificationService.Web.Controllers.Api.EmailTemplates;
|
||||
|
||||
public sealed record CreateEmailTemplateRequest(
|
||||
string ServiceName,
|
||||
string Key,
|
||||
string LanguageCode,
|
||||
string Subject,
|
||||
string HtmlBody,
|
||||
string TextBody,
|
||||
IReadOnlyList<EmailTemplateVariable> Variables
|
||||
);
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
using HrynCo.NotificationService.Web.Infrastructure;
|
||||
using HrynCo.NotificationService.Services.EmailTemplates.Create;
|
||||
using HrynCo.NotificationService.Services.EmailTemplates.Delete;
|
||||
using HrynCo.NotificationService.Services.EmailTemplates.Get;
|
||||
using HrynCo.NotificationService.Services.EmailTemplates.GetByService;
|
||||
using HrynCo.NotificationService.Services.EmailTemplates.Update;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace HrynCo.NotificationService.Web.Controllers.Api.EmailTemplates;
|
||||
|
||||
[Route("api/v1/email-templates")]
|
||||
public sealed class EmailTemplatesController : ApiControllerBase
|
||||
{
|
||||
public EmailTemplatesController(IMediator mediator) : base(mediator) { }
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] string serviceName, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await Mediator.Send(new GetEmailTemplatesQuery(serviceName), cancellationToken);
|
||||
return FromServiceResult(result);
|
||||
}
|
||||
|
||||
[HttpGet("{serviceName}/{key}/{languageCode}")]
|
||||
public async Task<IActionResult> Get(string serviceName, string key, string languageCode, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await Mediator.Send(new GetEmailTemplateQuery(serviceName, key, languageCode), cancellationToken);
|
||||
return FromServiceResult(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateEmailTemplateRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var command = new CreateEmailTemplateCommand(
|
||||
request.ServiceName,
|
||||
request.Key,
|
||||
request.LanguageCode,
|
||||
request.Subject,
|
||||
request.HtmlBody,
|
||||
request.TextBody,
|
||||
request.Variables
|
||||
);
|
||||
|
||||
var result = await Mediator.Send(command, cancellationToken);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
return MapServiceError(result.Error!);
|
||||
|
||||
return CreatedAtAction(
|
||||
nameof(Get),
|
||||
new { serviceName = request.ServiceName, key = request.Key, languageCode = request.LanguageCode },
|
||||
new ApiResponse<Guid> { Success = true, Data = result.Result }
|
||||
);
|
||||
}
|
||||
|
||||
[HttpPut("{serviceName}/{key}/{languageCode}")]
|
||||
public async Task<IActionResult> Update(
|
||||
string serviceName,
|
||||
string key,
|
||||
string languageCode,
|
||||
[FromBody] UpdateEmailTemplateRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var command = new UpdateEmailTemplateCommand(
|
||||
serviceName,
|
||||
key,
|
||||
languageCode,
|
||||
request.Subject,
|
||||
request.HtmlBody,
|
||||
request.TextBody,
|
||||
request.Variables
|
||||
);
|
||||
|
||||
var result = await Mediator.Send(command, cancellationToken);
|
||||
return FromServiceResult(result);
|
||||
}
|
||||
|
||||
[HttpDelete("{serviceName}/{key}/{languageCode}")]
|
||||
public async Task<IActionResult> Delete(string serviceName, string key, string languageCode, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await Mediator.Send(new DeleteEmailTemplateCommand(serviceName, key, languageCode), cancellationToken);
|
||||
return FromServiceResult(result);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using HrynCo.NotificationService.DAL.Abstract.Templates;
|
||||
|
||||
namespace HrynCo.NotificationService.Web.Controllers.Api.EmailTemplates;
|
||||
|
||||
public sealed record UpdateEmailTemplateRequest(
|
||||
string Subject,
|
||||
string HtmlBody,
|
||||
string TextBody,
|
||||
IReadOnlyList<EmailTemplateVariable> Variables
|
||||
);
|
||||
Reference in New Issue
Block a user