BaseApiController.cs 810 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using JCSoft.WX.Framework.Api;
  6. using Microsoft.AspNetCore.Mvc;
  7. using JCSoft.WX.Framework.Models.ApiRequests;
  8. using JCSoft.WX.Framework.Models.ApiResponses;
  9. using Microsoft.Extensions.Caching.Memory;
  10. namespace SupplierWeb.Controllers
  11. {
  12. public abstract class BaseApiController<T> : BaseController
  13. where T : ApiResponse, new()
  14. {
  15. public BaseApiController(IMemoryCache cache, IApiClient client) : base(cache, client)
  16. {
  17. }
  18. public JsonResult Get()
  19. {
  20. var request = GetApiRequest();
  21. var response = _client.Execute(request);
  22. return Json(response);
  23. }
  24. protected abstract ApiRequest<T> GetApiRequest();
  25. }
  26. }