Files
social-media/backend/src/Socialize.Api/Modules/ReleaseCommunications/Handlers/CreateDeveloperReleaseUpdate.cs
Jonathan Bourdon dcfdce1ec6
Some checks failed
deploy-socialize / image (push) Successful in 1m9s
deploy-socialize / deploy (push) Has been cancelled
Simplify release notes workflow
2026-05-08 00:37:14 -04:00

60 lines
2.0 KiB
C#

using FastEndpoints;
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;
namespace Socialize.Api.Modules.ReleaseCommunications.Handlers;
internal record CreateDeveloperReleaseUpdateRequest(
string TitleEn,
string DescriptionEn,
string TitleFr,
string DescriptionFr);
internal class CreateDeveloperReleaseUpdateRequestValidator
: Validator<CreateDeveloperReleaseUpdateRequest>
{
public CreateDeveloperReleaseUpdateRequestValidator()
{
RuleFor(x => x.TitleEn).NotEmpty().MaximumLength(160);
RuleFor(x => x.DescriptionEn).NotEmpty().MaximumLength(4000);
RuleFor(x => x.TitleFr).NotEmpty().MaximumLength(160);
RuleFor(x => x.DescriptionFr).NotEmpty().MaximumLength(4000);
}
}
internal class CreateDeveloperReleaseUpdateHandler(AppDbContext dbContext)
: Endpoint<CreateDeveloperReleaseUpdateRequest, ReleaseUpdateDto>
{
public override void Configure()
{
Post("/api/developer/release-updates");
Roles(KnownRoles.Developer);
Options(o => o.WithTags("Release Communications"));
}
public override async Task HandleAsync(CreateDeveloperReleaseUpdateRequest request, CancellationToken ct)
{
DateTimeOffset now = DateTimeOffset.UtcNow;
ReleaseUpdate update = new()
{
Id = Guid.NewGuid(),
Title = request.TitleEn.Trim(),
Summary = request.DescriptionEn.Trim(),
TitleFr = request.TitleFr.Trim(),
SummaryFr = request.DescriptionFr.Trim(),
Status = ReleaseUpdateStatus.Draft,
CreatedByUserId = User.GetUserId(),
CreatedAt = now,
UpdatedAt = now,
};
dbContext.ReleaseUpdates.Add(update);
await dbContext.SaveChangesAsync(ct);
await SendAsync(update.ToDto(false), StatusCodes.Status201Created, ct);
}
}