34 lines
920 B
C#
34 lines
920 B
C#
using BeReadyBackend.Repositories;
|
|
using BeReadyBackend.Specifications.Groups;
|
|
using FastEndpoints;
|
|
using Group = BeReadyBackend.Models.Group;
|
|
|
|
namespace BeReadyBackend.Endpoints.Groups;
|
|
|
|
public class StatusRequest
|
|
{
|
|
public int GroupId { get; set; }
|
|
}
|
|
|
|
public class PatchGroupStatusEndpoint(GroupsRepository groupsRepository) : Endpoint<StatusRequest>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Patch("/Groups/{@GroupId}/Status/", x => new { x.GroupId });
|
|
}
|
|
|
|
public override async Task HandleAsync(StatusRequest req, CancellationToken ct)
|
|
{
|
|
Group? group = await groupsRepository.SingleOrDefaultAsync(new GetGroupByIdSpec(req.GroupId), ct);
|
|
|
|
if (group is null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
group.IsFinished = true;
|
|
await groupsRepository.SaveChangesAsync(ct);
|
|
await Send.NoContentAsync(ct);
|
|
}
|
|
} |