SundryModel.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using economy.Helpers;
  2. namespace economy.Models.Sundry
  3. {
  4. public class SundryModel
  5. {
  6. private readonly DataGoKR _dataGoKR;
  7. public SundryModel(DataGoKR dataGoKR)
  8. {
  9. _dataGoKR = dataGoKR;
  10. }
  11. // 잡절 조회
  12. public async Task<Response> GetSundry(Request request)
  13. {
  14. Response parseData = new();
  15. try
  16. {
  17. var uriBuilder = new UriBuilder(_dataGoKR.APIUrl)
  18. {
  19. Path = "/B090041/openapi/service/SpcdeInfoService/getSundryDayInfo",
  20. Query = $"ServiceKey={_dataGoKR.APIKey}&numOfRows=100&solYear={request.Year}"
  21. };
  22. var response = await _dataGoKR.httpClient.GetAsync(uriBuilder.Uri);
  23. if (response.IsSuccessStatusCode)
  24. {
  25. var xmlString = await response.Content.ReadAsStringAsync();
  26. parseData = await Common.ParseXmlDataAsync<Response>(xmlString);
  27. if (parseData.Body is null)
  28. {
  29. return new Response();
  30. }
  31. }
  32. response.EnsureSuccessStatusCode();
  33. }
  34. catch (HttpRequestException e)
  35. {
  36. Console.WriteLine($"Request error: {e.Message}");
  37. }
  38. return parseData;
  39. }
  40. }
  41. }