56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Socialize.Api.Data;
|
|
using Socialize.Api.Infrastructure.Security;
|
|
using Socialize.Api.Modules.Identity.Contracts;
|
|
using Socialize.Api.Modules.ReleaseCommunications.Contracts;
|
|
using Socialize.Api.Modules.ReleaseCommunications.Data;
|
|
using Socialize.Api.Modules.ReleaseCommunications.Services;
|
|
|
|
namespace Socialize.Api.Modules.ReleaseCommunications.Handlers;
|
|
|
|
internal record SendDeveloperReleaseUpdateEmailRequest(
|
|
bool TestMode,
|
|
bool ConfirmResend);
|
|
|
|
internal class SendDeveloperReleaseUpdateEmailHandler(
|
|
AppDbContext dbContext,
|
|
ReleaseUpdateEmailService emailService)
|
|
: Endpoint<SendDeveloperReleaseUpdateEmailRequest, ReleaseUpdateEmailSendResultDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/api/developer/release-updates/{id}/send-email");
|
|
Roles(KnownRoles.Developer);
|
|
Options(o => o.WithTags("Release Communications"));
|
|
}
|
|
|
|
public override async Task HandleAsync(SendDeveloperReleaseUpdateEmailRequest request, CancellationToken ct)
|
|
{
|
|
Guid id = Route<Guid>("id");
|
|
ReleaseUpdate? update = await dbContext.ReleaseUpdates.SingleOrDefaultAsync(candidate => candidate.Id == id, ct);
|
|
if (update is null)
|
|
{
|
|
await SendNotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
ReleaseUpdateEmailSendResultDto result = await emailService.SendManualUpdateEmailAsync(
|
|
update,
|
|
User.GetUserId(),
|
|
request.TestMode,
|
|
request.ConfirmResend,
|
|
ct);
|
|
await dbContext.SaveChangesAsync(ct);
|
|
await SendOkAsync(result, ct);
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
AddError(ex.Message);
|
|
await SendErrorsAsync(StatusCodes.Status400BadRequest, ct);
|
|
}
|
|
}
|
|
}
|