Adds ChangeAbout for Creators

This commit is contained in:
Jonathan Bourdon
2024-08-07 02:19:04 -04:00
parent 162063facd
commit 6d9201e8aa

View File

@@ -0,0 +1,40 @@
using FastEndpoints;
using Hutopy.Web.Features.Contents.Data;
using Microsoft.EntityFrameworkCore;
namespace Hutopy.Web.Features.Contents.Handlers;
public record ChangeAboutRequest(
Guid CreatorId,
string? Title,
string? Description);
public class ChangeAboutHandler(
ContentDbContext context)
: Endpoint<ChangeAboutRequest>
{
public override void Configure()
{
Post("/api/creators/{CreatorId}/about");
Options(o => o.WithTags("Contents"));
}
public override async Task HandleAsync(
ChangeAboutRequest request,
CancellationToken ct)
{
var creator = await context
.Creators
.Include(c => c.About)
.SingleAsync(
c => c.Id == request.CreatorId,
cancellationToken: ct);
creator.About.Title = request.Title;
creator.About.Description = request.Description;
await context.SaveChangesAsync(ct);
await SendOkAsync(ct);
}
}