using System.Collections.Generic; using Luticate2.Utils.Dbo.Basic; using Luticate2.Utils.Dbo.Result; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; namespace Luticate2.Utils.Controllers { public abstract class LuController : Controller { protected readonly LuUtilsOptionsDbo LuUtilsOptionsDbo; protected IDictionary LuItems => HttpContext.GetLuItems(); protected LuController(IOptions luUtilsOptionsDbo) { LuUtilsOptionsDbo = luUtilsOptionsDbo.Value; } protected virtual LuApiWrapperDbo Handle(LuResult result) { if (result) { return new LuApiWrapperDbo { code = 200, data = result.Data, message = null, version = LuUtilsOptionsDbo.Version }; } result.Throw(); return null; } protected virtual LuApiWrapperDbo> HandleBoxed(LuResult result) { return Handle(result.To(arg => new LuBoxedValueDbo { Value = arg })); } } }