using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.ItemModel; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.ItemModel { public class GetItemModel : BaseEndpoint> { private readonly IItemModelBLL _ItemModelBLL; public GetItemModel(IItemModelBLL IItemModelBLL) { _ItemModelBLL = IItemModelBLL; } public override void Configure() { Get("/ItemModel/GetItemModel"); AllowAnonymous(); } public record GetItemModelParameters( [property: FromHeader] string Login, [property: QueryParam] int ModelId ); protected override string? GetCacheKey(GetItemModelParameters Parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(Parameters.ModelId!, EntityConstant.OBJECTMODEL, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetItemModelParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _ItemModelBLL.GetItemModel(req.ModelId, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.USER_LEVEL, LoginDTO, ex.Message, 500); } } } }