using FastEndpoints;
using FrameworkBLL.MenuGroup;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.FastEndPoint;
using static GB5Shared.GB5Constant.Constant;
namespace FrameworkSL.Endpoints.MenuGroup
{
///
/// New sibling to GetMenuForUserModule/GetMenuListBasedMenuSetForTree — added rather than
/// modifying either in place, so those hot, currently-uncached, production paths carry zero
/// regression risk from this feature. Callers on a PRESENTATIONTYPE=1/2 MenuSet should call
/// this instead; PRESENTATIONTYPE=0 callers can keep using the existing endpoints unchanged
/// (this endpoint also handles that case by delegating, but isn't the required migration path).
///
public class GetMenuGroupTree : BaseEndpoint>
{
private readonly IMenuGroupBLL _menuGroupBLL;
public GetMenuGroupTree(IMenuGroupBLL menuGroupBLL) => _menuGroupBLL = menuGroupBLL;
public override void Configure()
{
Get("/MenuGroup/GetMenuGroupTree");
AllowAnonymous();
}
public record GetMenuGroupTreeParameters(
[property: FromHeader] string Login,
[property: QueryParam] int MenuSetId
);
// Keyed on MenuSetId alone (not MenuSetId+RoleId as a literal per-role cache would
// require) — see MenuGroupBLL's caching remarks for why: this keeps invalidation to
// one key per write instead of an unbounded per-role fanout. This endpoint's resolution
// order (gb5_menu_presentation_layer.sql) does not itself filter by role.
protected override string? GetCacheKey(GetMenuGroupTreeParameters req, LoginDTO loginDTO)
=> KeyGenerator.KeyGeneration(req.MenuSetId, EntityConstant.OBJECTMENUGROUP, CacheKeyLevel.CLIENT_LEVEL, loginDTO);
protected override async Task> ExecuteAsync(
GetMenuGroupTreeParameters req, LoginDTO loginDTO, CancellationToken ct)
{
var result = await _menuGroupBLL.GetMenuGroupTreeForSet(req.MenuSetId, loginDTO, ct);
return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, loginDTO);
}
}
}