Adds ChangeAbout for Creators
This commit is contained in:
40
src/Web/Features/Contents/Handlers/ChangeAbout.cs
Normal file
40
src/Web/Features/Contents/Handlers/ChangeAbout.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user