switching back to httpclient instead of db direct

This commit is contained in:
Hamid Reza Mohammadi 2021-05-17 12:49:31 +04:30
parent cf3b10549c
commit d93ae0c89a

View File

@ -1,24 +1,27 @@
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using RMuseum.Models.Ganjoor.ViewModels;
using RMuseum.Models.GanjoorAudio.ViewModels;
using RMuseum.Services;
namespace GanjooRazor.Pages
{
public class AudioClipModel : PageModel
{
/// <summary>
/// HttpClient instance
/// </summary>
private readonly HttpClient _httpClient;
private readonly IGanjoorService _ganjoorService;
private readonly IRecitationService _recitationService;
public AudioClipModel(IGanjoorService ganjoorService, IRecitationService recitationService)
/// <summary>
/// constructor
/// </summary>
/// <param name="httpClient"></param>
public AudioClipModel(HttpClient httpClient)
{
_ganjoorService = ganjoorService;
_recitationService = recitationService;
_httpClient = httpClient;
}
/// <summary>
@ -38,14 +41,15 @@ namespace GanjooRazor.Pages
return BadRequest();
}
var res = await _recitationService.GetPublishedRecitationById(int.Parse(Request.Query["a"]));
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/audio/published/{Request.Query["a"]}");
response.EnsureSuccessStatusCode();
Recitation = JsonConvert.DeserializeObject<PublicRecitationViewModel>(await response.Content.ReadAsStringAsync());
Recitation = res.Result;
var responsePoem = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{Recitation.PoemId}?verseDetails=true&catInfo=true&rhymes=false&recitations=false&images=false&songs=false&comments=false&navigation=false");
responsePoem.EnsureSuccessStatusCode();
var resPoem = await _ganjoorService.GetPoemById(Recitation.PoemId, true, false, false, false, false, false, false, true, false);
Poem = resPoem.Result;
Poem = JsonConvert.DeserializeObject<GanjoorPoemCompleteViewModel>(await responsePoem.Content.ReadAsStringAsync());
return Page();