From 6d9201e8aadd97d8d66a2263946d1ab1f266edb6 Mon Sep 17 00:00:00 2001 From: Jonathan Bourdon Date: Wed, 7 Aug 2024 02:19:04 -0400 Subject: [PATCH] Adds ChangeAbout for Creators --- .../Features/Contents/Handlers/ChangeAbout.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Web/Features/Contents/Handlers/ChangeAbout.cs diff --git a/src/Web/Features/Contents/Handlers/ChangeAbout.cs b/src/Web/Features/Contents/Handlers/ChangeAbout.cs new file mode 100644 index 0000000..0cbe19c --- /dev/null +++ b/src/Web/Features/Contents/Handlers/ChangeAbout.cs @@ -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 +{ + 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); + } +}