Changements dans le Group Model + endpoints Patch des Groupes et Users
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using FastEndpoints;
|
||||
using Knots.DTO.Group;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Knots.Endpoints.Group;
|
||||
|
||||
public class PatchGroupProfilePictureEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateGroupProfilePictureDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/groups/{@Id}/profilePicture/", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateGroupProfilePictureDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Group? databaseGroup = await knotsDbContext.Groups.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||
|
||||
if (databaseGroup is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
databaseGroup.ProfilePicture = req.ProfilePicture;
|
||||
await knotsDbContext.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user