using AdminBLL.AllocationType; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AdminSL.EndPoints.AllocationType { public class DeleteAllocationType : BaseEndpoint> { public readonly IAllocationTypeBLL _AllocationTypeBLL; public DeleteAllocationType(IAllocationTypeBLL IAllocationTypeBLL) { _AllocationTypeBLL = IAllocationTypeBLL; } public override void Configure() { Delete("/AllocationType/DeleteAllocationType"); AllowAnonymous(); } public record DeleteAllocationTypeParameters( [property: FromHeader] string Login, [property: QueryParam] int AllocationTypeId ); protected override string? GetCacheKey( DeleteAllocationTypeParameters req, LoginDTO loginDTO) { if (req.AllocationTypeId <= 0) return null; return KeyGenerator.KeyGeneration( req.AllocationTypeId, EntityConstant.OBJECTALLOCATION, CacheKeyLevel.USER_LEVEL, loginDTO ); } // 🔥 IMPORTANT PART 2: DELETE always invalidates cache protected override bool ShouldInvalidateCache( DeleteAllocationTypeParameters req, LoginDTO loginDTO) { return true; } protected override async Task> ExecuteAsync(DeleteAllocationTypeParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _AllocationTypeBLL.DeleteAllocationType(req.AllocationTypeId, LoginDTO!); 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); } } } }