123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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<object, object> LuItems => HttpContext.GetLuItems();
-
- protected LuController(IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo)
- {
- LuUtilsOptionsDbo = luUtilsOptionsDbo.Value;
- }
-
- protected virtual LuApiWrapperDbo<T> Handle<T>(LuResult<T> result)
- {
- if (result)
- {
- return new LuApiWrapperDbo<T>
- {
- code = 200,
- data = result.Data,
- message = null,
- version = LuUtilsOptionsDbo.Version
- };
- }
- throw new LuResultException(result.To<object>());
- }
-
- protected virtual LuApiWrapperDbo<LuBoxedValueDbo<T>> HandleBoxed<T>(LuResult<T> result)
- {
- return Handle(result.To(arg => new LuBoxedValueDbo<T>
- {
- Value = arg
- }));
- }
- }
- }
|