From a7761bb668b5425add6f157e6bb2a46e7f73be0e Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 10 May 2021 20:01:23 +0430 Subject: [PATCH] #112 removing internal httpclient call from spotify search --- GanjooRazor/Pages/Spotify.cshtml.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/GanjooRazor/Pages/Spotify.cshtml.cs b/GanjooRazor/Pages/Spotify.cshtml.cs index 65fcc94a..18bbe882 100644 --- a/GanjooRazor/Pages/Spotify.cshtml.cs +++ b/GanjooRazor/Pages/Spotify.cshtml.cs @@ -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 /// private readonly HttpClient _httpClient; + /// + /// ganjoor service + /// + private readonly IGanjoorService _ganjoorService; + /// /// constructor /// /// - public SpotifyModel(HttpClient httpClient) + /// + public SpotifyModel(HttpClient httpClient, IGanjoorService ganjoorService) { _httpClient = httpClient; + _ganjoorService = ganjoorService; } /// @@ -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 res = + await _ganjoorService.GetPoemSongs(PoemId, false, PoemMusicTrackType.Spotify); + if (string.IsNullOrEmpty(res.ExceptionString)) { - SuggestedSongs = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + SuggestedSongs = res.Result; } else {