using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using GB5Shared.ListQuery; using PIEDAL.DTO.ConfigItem; using static GB5Shared.GB5Constant.Constant; namespace PIESL.EndPoints.ConfigItem { public class GetPIEConfigItemList : BaseEndpoint> { private readonly IListHandler _ListHandler; public GetPIEConfigItemList(IListHandler listHandler) { _ListHandler = listHandler; } public override void Configure() { Post("/PIE/GetPIEConfigItemList"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: QueryParam] Guid? ModuleId = null, [property: QueryParam] string? ItemCategory = null, [property: QueryParam] bool? IsMandatory = null, [property: QueryParam] bool? IsActive = null, [property: QueryParam] string? SearchText = null, [property: QueryParam] string? SortBy = null, [property: QueryParam] bool SortDesc = false, [property: QueryParam] int PageOffset = 0, [property: QueryParam] int PageSize = 100 ); protected override string? GetCacheKey(Params req, LoginDTO loginDTO) => KeyGenerator.KeyGeneration(loginDTO.ClientId, EntityConstant.OBJECTPIECONFIGITEM, CacheKeyLevel.CLIENT_LEVEL, loginDTO); protected override async Task> ExecuteAsync(Params req, LoginDTO loginDTO, CancellationToken ct) { var criteria = new PIEConfigItemListCriteria { ModuleId = req.ModuleId, ItemCategory = req.ItemCategory, IsMandatory = req.IsMandatory is null ? null : (short?)(req.IsMandatory.Value ? 1 : 0), IsActive = req.IsActive is null ? null : (short?)(req.IsActive.Value ? 1 : 0), SearchText = req.SearchText, SortBy = req.SortBy, SortDesc = req.SortDesc, PageOffset = req.PageOffset, PageSize = req.PageSize }; var result = await _ListHandler.HandleAsync(new PIEConfigItemListQuery(criteria), loginDTO, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, loginDTO); } } }