1- using Microsoft . Extensions . Configuration ;
1+ using Microsoft . AspNetCore . WebUtilities ;
2+ using Microsoft . Extensions . Configuration ;
23using SamSmithNZ . Service . Models . FooFighters ;
34using SamSmithNZ . Web . Services . Interfaces ;
45using System ;
@@ -12,13 +13,10 @@ public class FooFightersServiceApiClient : BaseServiceApiClient, IFooFightersSer
1213 {
1314 private readonly IConfiguration _configuration ;
1415
15- public FooFightersServiceApiClient ( IConfiguration configuration )
16+ public FooFightersServiceApiClient ( IConfiguration configuration , HttpClient client )
1617 {
1718 _configuration = configuration ;
18- HttpClient client = new ( )
19- {
20- BaseAddress = new ( _configuration [ "AppSettings:WebServiceURL" ] )
21- } ;
19+ client . BaseAddress = new Uri ( _configuration [ "AppSettings:WebServiceURL" ] ) ;
2220 base . SetupClient ( client ) ;
2321 }
2422
@@ -38,7 +36,8 @@ public async Task<List<Album>> GetAlbums()
3836
3937 public async Task < Album > GetAlbum ( int albumCode )
4038 {
41- Uri url = new ( $ "api/FooFighters/Album/GetAlbum?AlbumCode=" + albumCode , UriKind . Relative ) ;
39+ string albumUrl = QueryHelpers . AddQueryString ( "api/FooFighters/Album/GetAlbum" , "AlbumCode" , albumCode . ToString ( ) ) ;
40+ Uri url = new ( albumUrl , UriKind . Relative ) ;
4241 Album result = await base . ReadMessageItem < Album > ( url ) ;
4342 if ( result == null )
4443 {
@@ -52,7 +51,14 @@ public async Task<Album> GetAlbum(int albumCode)
5251
5352 public async Task < List < AverageSetlist > > GetAverageSetlist ( int yearCode , int minimumSongCount = 0 , bool showAllSongs = false )
5453 {
55- Uri url = new ( $ "api/FooFighters/AverageSetlist/GetAverageSetlist?YearCode=" + yearCode + "&MinimumSongCount=" + minimumSongCount + "&showAllSongs=" + showAllSongs , UriKind . Relative ) ;
54+ Dictionary < string , string > queryParams = new Dictionary < string , string >
55+ {
56+ { "YearCode" , yearCode . ToString ( ) } ,
57+ { "MinimumSongCount" , minimumSongCount . ToString ( ) } ,
58+ { "showAllSongs" , showAllSongs . ToString ( ) }
59+ } ;
60+ string averageSetlistUrl = QueryHelpers . AddQueryString ( "api/FooFighters/AverageSetlist/GetAverageSetlist" , queryParams ) ;
61+ Uri url = new ( averageSetlistUrl , UriKind . Relative ) ;
5662 List < AverageSetlist > results = await base . ReadMessageList < AverageSetlist > ( url ) ;
5763 if ( results == null )
5864 {
@@ -66,7 +72,8 @@ public async Task<List<AverageSetlist>> GetAverageSetlist(int yearCode, int mini
6672
6773 public async Task < List < Show > > GetShowsByYear ( int yearCode )
6874 {
69- Uri url = new ( $ "api/FooFighters/Show/GetShowsByYear?YearCode=" + yearCode , UriKind . Relative ) ;
75+ string showsByYearUrl = QueryHelpers . AddQueryString ( "api/FooFighters/Show/GetShowsByYear" , "YearCode" , yearCode . ToString ( ) ) ;
76+ Uri url = new ( showsByYearUrl , UriKind . Relative ) ;
7077 List < Show > results = await base . ReadMessageList < Show > ( url ) ;
7178 if ( results == null )
7279 {
@@ -80,7 +87,8 @@ public async Task<List<Show>> GetShowsByYear(int yearCode)
8087
8188 public async Task < List < Show > > GetShowsBySong ( int songCode )
8289 {
83- Uri url = new ( $ "api/FooFighters/Show/GetShowsBySong?SongCode=" + songCode , UriKind . Relative ) ;
90+ string showsBySongUrl = QueryHelpers . AddQueryString ( "api/FooFighters/Show/GetShowsBySong" , "SongCode" , songCode . ToString ( ) ) ;
91+ Uri url = new ( showsBySongUrl , UriKind . Relative ) ;
8492 List < Show > results = await base . ReadMessageList < Show > ( url ) ;
8593 if ( results == null )
8694 {
@@ -94,7 +102,8 @@ public async Task<List<Show>> GetShowsBySong(int songCode)
94102
95103 public async Task < Show > GetShow ( int showCode )
96104 {
97- Uri url = new ( $ "api/FooFighters/Show/GetShow?ShowCode=" + showCode , UriKind . Relative ) ;
105+ string showUrl = QueryHelpers . AddQueryString ( "api/FooFighters/Show/GetShow" , "ShowCode" , showCode . ToString ( ) ) ;
106+ Uri url = new ( showUrl , UriKind . Relative ) ;
98107 Show result = await base . ReadMessageItem < Show > ( url ) ;
99108 if ( result == null )
100109 {
@@ -122,7 +131,8 @@ public async Task<List<Song>> GetSongs()
122131
123132 public async Task < List < Song > > GetSongsByAlbum ( int albumCode )
124133 {
125- Uri url = new ( $ "api/FooFighters/Song/GetSongsByAlbum?AlbumCode=" + albumCode , UriKind . Relative ) ;
134+ string songsByAlbumUrl = QueryHelpers . AddQueryString ( "api/FooFighters/Song/GetSongsByAlbum" , "AlbumCode" , albumCode . ToString ( ) ) ;
135+ Uri url = new ( songsByAlbumUrl , UriKind . Relative ) ;
126136 List < Song > results = await base . ReadMessageList < Song > ( url ) ;
127137 if ( results == null )
128138 {
@@ -136,7 +146,8 @@ public async Task<List<Song>> GetSongsByAlbum(int albumCode)
136146
137147 public async Task < List < Song > > GetSongsByShow ( int showCode )
138148 {
139- Uri url = new ( $ "api/FooFighters/Song/GetSongsByShow?ShowCode=" + showCode , UriKind . Relative ) ;
149+ string songsByShowUrl = QueryHelpers . AddQueryString ( "api/FooFighters/Song/GetSongsByShow" , "ShowCode" , showCode . ToString ( ) ) ;
150+ Uri url = new ( songsByShowUrl , UriKind . Relative ) ;
140151 List < Song > results = await base . ReadMessageList < Song > ( url ) ;
141152 if ( results == null )
142153 {
@@ -150,7 +161,8 @@ public async Task<List<Song>> GetSongsByShow(int showCode)
150161
151162 public async Task < Song > GetSong ( int songCode )
152163 {
153- Uri url = new ( $ "api/FooFighters/Song/GetSong?SongCode=" + songCode , UriKind . Relative ) ;
164+ string songUrl = QueryHelpers . AddQueryString ( "api/FooFighters/Song/GetSong" , "SongCode" , songCode . ToString ( ) ) ;
165+ Uri url = new ( songUrl , UriKind . Relative ) ;
154166 Song result = await base . ReadMessageItem < Song > ( url ) ;
155167 if ( result == null )
156168 {
0 commit comments