using HrynCo.NotificationService.Services.EmailChannels.Create; using HrynCo.NotificationService.Services.EmailChannels.Delete; using HrynCo.NotificationService.Services.EmailChannels.Get; using HrynCo.NotificationService.Services.EmailChannels.GetByService; using HrynCo.NotificationService.Services.EmailChannels.Update; using MediatR; using Microsoft.AspNetCore.Mvc; namespace HrynCo.NotificationService.Api.Controllers.EmailChannels; [Route("api/v1/email-channels")] public sealed class EmailChannelsController : ApiControllerBase { public EmailChannelsController(IMediator mediator) : base(mediator) { } [HttpGet] public async Task GetAll([FromQuery] string serviceName, CancellationToken cancellationToken) { var result = await Mediator.Send(new GetEmailChannelsQuery(serviceName), cancellationToken); return FromServiceResult(result); } [HttpGet("{id:guid}")] public async Task Get(Guid id, CancellationToken cancellationToken) { var result = await Mediator.Send(new GetEmailChannelQuery(id), cancellationToken); return FromServiceResult(result); } [HttpPost] public async Task Create([FromBody] CreateEmailChannelRequest request, CancellationToken cancellationToken) { var command = new CreateEmailChannelCommand( request.ServiceName, request.Priority, request.ChannelType, request.Settings, request.DailyLimit, request.MonthlyLimit, request.WarnThresholdPercent, request.IsActive ); var result = await Mediator.Send(command, cancellationToken); if (!result.IsSuccess) return MapServiceError(result.Error!); return CreatedAtAction(nameof(Get), new { id = result.Result }, result.Result); } [HttpPut("{id:guid}")] public async Task Update(Guid id, [FromBody] UpdateEmailChannelRequest request, CancellationToken cancellationToken) { var command = new UpdateEmailChannelCommand( id, request.Priority, request.Settings, request.DailyLimit, request.MonthlyLimit, request.WarnThresholdPercent, request.IsActive ); var result = await Mediator.Send(command, cancellationToken); return FromServiceResult(result); } [HttpDelete("{id:guid}")] public async Task Delete(Guid id, CancellationToken cancellationToken) { var result = await Mediator.Send(new DeleteEmailChannelCommand(id), cancellationToken); return FromServiceResult(result); } }