Initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using FastEndpoints;
|
||||
using MetaCourse.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MetaCourse.Api.Endpoints.Topics;
|
||||
|
||||
public class DeleteTopicRequest
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteTopicEndpoint(AppDbContext db) : Endpoint<DeleteTopicRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("api/topics/{id}");
|
||||
AllowAnonymous();
|
||||
Summary(s => s.Summary = "Supprime un sujet et ses associations de ressources");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteTopicRequest req, CancellationToken ct)
|
||||
{
|
||||
var topic = await db.Topics.FirstOrDefaultAsync(t => t.Id == req.Id, ct);
|
||||
if (topic is null)
|
||||
{
|
||||
await SendNotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
db.Topics.Remove(topic);
|
||||
await db.SaveChangesAsync(ct);
|
||||
await SendNoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user