29 lines
889 B
C#
29 lines
889 B
C#
using FastEndpoints;
|
|
using Knots.DTO.Group;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Knots.Endpoints.Group;
|
|
|
|
public class PatchGroupMembersAmountEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateGroupMembersAmountDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Patch("/groups/{@Id}/membersAmount/", x => new {x.Id});
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(UpdateGroupMembersAmountDto req, CancellationToken ct)
|
|
{
|
|
Models.Group? databaseGroup = await knotsDbContext.Groups.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
|
|
if (databaseGroup is null)
|
|
{
|
|
await SendNotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
databaseGroup.MembersAmount = req.MembersAmount;
|
|
await knotsDbContext.SaveChangesAsync(ct);
|
|
await SendNoContentAsync(ct);
|
|
}
|
|
} |