using FastEndpoints; using FrameworkBLL.EntityViewer; using GB5Shared.DTO.Framework.Login; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.EntityViewer { // POST /EntityViewer/DeleteEntityLayoutVersion // // Discards a Draft version that was never activated (soft delete). Fails with a clear // error if the version is already Active or Archived — those are permanent history. public class DeleteEntityLayoutVersion : BaseEndpoint> { private readonly IEntityLayoutBLL _Bll; public DeleteEntityLayoutVersion(IEntityLayoutBLL bll) => _Bll = bll; public override void Configure() { Post("/EntityViewer/DeleteEntityLayoutVersion"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: FromBody] DeleteRequest Request ); public record DeleteRequest(int EntityLayoutVersionId); protected override string? GetCacheKey(Params req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( Params req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _Bll.DeleteLayoutVersion(req.Request.EntityLayoutVersionId, loginDTO, ct); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }