35 lines
912 B
C#
35 lines
912 B
C#
namespace PyroFetes.Endpoint.Setting;
|
|
using PyroFetes.DTO.SettingDTO.Request;
|
|
using PyroFetes.DTO.SettingDTO.Response;
|
|
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
public class DeleteSettingRequest
|
|
{
|
|
public int Id { get; set; }
|
|
}
|
|
|
|
|
|
public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSettingRequest>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Delete("/api/setting/{@Id}", x => new {x.Id});
|
|
}
|
|
|
|
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
|
|
{
|
|
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
|
|
if (setting == null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
database.Settings.Remove(setting);
|
|
await database.SaveChangesAsync(ct);
|
|
|
|
await Send.NoContentAsync(ct);
|
|
}
|
|
} |