using AdminBLL.AllocationType; using AdminDAL.DTO.Allocation; 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 SaveAllocationType : BaseEndpoint> { private readonly IAllocationTypeBLL _AllocationTypeBLL; public SaveAllocationType(IAllocationTypeBLL AllocationTypeBLL) { _AllocationTypeBLL = AllocationTypeBLL; } public override void Configure() { Post("/AllocationType/SaveAllocationType"); AllowAnonymous(); } public record SaveAllocationTypeParameters( [property: FromHeader] string Login, [property: FromBody] AllocationTypeDTO AllocationTypeDTO ); protected override string? GetCacheKey( SaveAllocationTypeParameters req, LoginDTO loginDTO) { // New record → no cache exists yet if (req.AllocationTypeDTO.AllocationTypeId <= 0) return null; return KeyGenerator.KeyGeneration( req.AllocationTypeDTO.AllocationTypeId, EntityConstant.OBJECTALLOCATION, CacheKeyLevel.USER_LEVEL, loginDTO ); } protected override bool ShouldInvalidateCache( SaveAllocationTypeParameters req, LoginDTO loginDTO) { return true; // SAVE always invalidates cache } protected override async Task> ExecuteAsync(SaveAllocationTypeParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _AllocationTypeBLL.SaveAllocationType(req.AllocationTypeDTO, 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); } } } }