#112 removing internal httpclient call from spotify search

This commit is contained in:
Hamid Reza Mohammadi 2021-05-10 20:01:23 +04:30
parent 62b1351103
commit a7761bb668

View File

@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Newtonsoft.Json;
using RMuseum.Models.Ganjoor;
using RMuseum.Models.Ganjoor.ViewModels;
using RMuseum.Services;
using RSecurityBackend.Models.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
@ -23,13 +25,20 @@ namespace GanjooRazor.Pages
/// </summary>
private readonly HttpClient _httpClient;
/// <summary>
/// ganjoor service
/// </summary>
private readonly IGanjoorService _ganjoorService;
/// <summary>
/// constructor
/// </summary>
/// <param name="httpClient"></param>
public SpotifyModel(HttpClient httpClient)
/// <param name="ganjoorService"></param>
public SpotifyModel(HttpClient httpClient, IGanjoorService ganjoorService)
{
_httpClient = httpClient;
_ganjoorService = ganjoorService;
}
/// <summary>
@ -71,11 +80,11 @@ namespace GanjooRazor.Pages
private async Task _GetSuggestedSongs()
{
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{PoemId}/songs/?approved=false&trackType={(int)PoemMusicTrackType.Spotify}");
if (response.StatusCode == HttpStatusCode.OK)
RServiceResult<PoemMusicTrackViewModel[]> res =
await _ganjoorService.GetPoemSongs(PoemId, false, PoemMusicTrackType.Spotify);
if (string.IsNullOrEmpty(res.ExceptionString))
{
SuggestedSongs = JsonConvert.DeserializeObject<PoemMusicTrackViewModel[]>(await response.Content.ReadAsStringAsync());
SuggestedSongs = res.Result;
}
else
{