Add 'backend/' from commit '040cfd7a75423d4e6136e58a67b40579af4ee966'
git-subtree-dir: backend git-subtree-mainline:ab911955edgit-subtree-split:040cfd7a75
This commit is contained in:
36
backend/src/Web/Features/Contents/Handlers/RemoveReaction.cs
Normal file
36
backend/src/Web/Features/Contents/Handlers/RemoveReaction.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Hutopy.Web.Features.Contents.Data;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
|
||||
[PublicAPI]
|
||||
public sealed class RemoveReactionRequest
|
||||
{
|
||||
public required Guid ContentId { get; set; }
|
||||
public required Guid UserId { get; set; }
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public class RemoveReaction(
|
||||
ContentDbContext context)
|
||||
: Endpoint<RemoveReactionRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/content/reaction/remove");
|
||||
Options(o => o.WithTags("Contents"));
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
RemoveReactionRequest req,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var content = await context.Contents
|
||||
.SingleAsync(x => x.Id == req.ContentId, ct);
|
||||
|
||||
var reaction = content.Reactions.Single(x => x.UserId == req.UserId);
|
||||
|
||||
content.Reactions.Remove(reaction);
|
||||
|
||||
await context.SaveChangesAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user