You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections.Generic;
  2. using Luticate2.Utils.Dbo.Basic;
  3. using Luticate2.Utils.Dbo.Result;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Options;
  6. namespace Luticate2.Utils.Controllers
  7. {
  8. public abstract class LuController : Controller
  9. {
  10. protected readonly LuUtilsOptionsDbo LuUtilsOptionsDbo;
  11. protected IDictionary<object, object> LuItems => HttpContext.GetLuItems();
  12. protected LuController(IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo)
  13. {
  14. LuUtilsOptionsDbo = luUtilsOptionsDbo.Value;
  15. }
  16. protected virtual LuApiWrapperDbo<T> Handle<T>(LuResult<T> result)
  17. {
  18. if (result)
  19. {
  20. return new LuApiWrapperDbo<T>
  21. {
  22. code = 200,
  23. data = result.Data,
  24. message = null,
  25. version = LuUtilsOptionsDbo.Version
  26. };
  27. }
  28. result.Throw();
  29. return null;
  30. }
  31. protected virtual LuApiWrapperDbo<LuBoxedValueDbo<T>> HandleBoxed<T>(LuResult<T> result)
  32. {
  33. return Handle(result.To(arg => new LuBoxedValueDbo<T>
  34. {
  35. Value = arg
  36. }));
  37. }
  38. }
  39. }