11using Asp . Versioning ;
22using Microsoft . AspNetCore . Http ;
33using Microsoft . AspNetCore . Mvc ;
4+ using Microsoft . AspNetCore . WebUtilities ;
45using Microsoft . Extensions . Options ;
56using System . Web ;
67using Umbraco . Cms . Integrations . Crm . ActiveCampaign . Configuration ;
@@ -21,7 +22,7 @@ public GetFormsByPageController(IOptions<ActiveCampaignSettings> options, IHttpC
2122 [ ProducesResponseType ( StatusCodes . Status404NotFound ) ]
2223 [ ProducesResponseType ( StatusCodes . Status403Forbidden ) ]
2324 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
24- public async Task < IActionResult > GetForms ( [ FromQuery ] int ? page = 1 , string ? searchQuery = "" )
25+ public async Task < IActionResult > GetForms ( [ FromQuery ] int ? page = 1 , [ FromQuery ] string ? searchQuery = "" )
2526 {
2627 var client = HttpClientFactory . CreateClient ( Constants . FormsHttpClient ) ;
2728
@@ -42,20 +43,17 @@ private string BuildRequestUri(string baseAddress, int page, string searchQuery)
4243 {
4344 var uri = $ "{ baseAddress } { ApiPath } ?limit={ Constants . DefaultPageSize } ";
4445
45- Dictionary < string , string > queryParamsDictionary = new Dictionary < string , string > ( ) ;
4646 if ( page > 1 )
4747 {
48- queryParamsDictionary . Add ( "offset" , ( ( page - 1 ) * Constants . DefaultPageSize ) . ToString ( ) ) ;
48+ uri = QueryHelpers . AddQueryString ( uri , "offset" , ( ( page - 1 ) * Constants . DefaultPageSize ) . ToString ( ) ) ;
4949 }
5050
5151 if ( ! string . IsNullOrWhiteSpace ( searchQuery ) )
5252 {
53- queryParamsDictionary . Add ( "search" , HttpUtility . UrlEncode ( searchQuery ) ) ;
53+ uri = QueryHelpers . AddQueryString ( uri , "search" , searchQuery ) ;
5454 }
5555
56- return queryParamsDictionary . Count == 0
57- ? uri
58- : string . Format ( "{0}&{1}" , uri , string . Join ( "&" , queryParamsDictionary . Select ( kvp => $ "{ kvp . Key } ={ kvp . Value } ") ) ) ;
56+ return uri ;
5957 }
6058 }
6159}
0 commit comments