using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using WiBLL.WiExecution; using static GB5Shared.GB5Constant.Constant; namespace WiSL.EndPoints.WiExecution { public class ResolveForEntity : BaseEndpoint> { private readonly IWiExecutionBLL _bll; public ResolveForEntity(IWiExecutionBLL bll) { _bll = bll; } public override void Configure() { Get("/Execution/ResolveForEntity"); AllowAnonymous(); } public record Parameters( [property: FromHeader] string Login, [property: QueryParam] int EntityType, [property: QueryParam] int EntityId, [property: QueryParam] int TriggerEvent ); // Same reasoning as ResolveForWorkstation: TTL-only, no exact-key invalidation. // TriggerEvent is a caller-supplied resolve input, not assignment data, so // SaveAssignment/DeleteAssignment cannot reconstruct which cached // (EntityType, EntityId, TriggerEvent) keys a saved/deleted row affects — // especially when that row's EntityId is itself a -1 wildcard matching many // concrete entities. A 5-minute staleness window is an acceptable tradeoff for // "which SOP applies here" content, not a correctness/safety concern. protected override string? GetCacheKey(Parameters req, LoginDTO login) => $"Wi:ResolveEntity:{login.ClientId}:{req.EntityType}:{req.EntityId}:{req.TriggerEvent}"; protected override int GetTtlSeconds() => TtlForLevel(CacheKeyLevel.CLIENT_LEVEL); protected override async Task> ExecuteAsync( Parameters req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.ResolveForEntity(req.EntityType, req.EntityId, (WiDAL.DTOs.TriggerEvent)req.TriggerEvent, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.CLIENT_LEVEL, login, ex.Message, 500); } } } }