@@ -23,9 +23,9 @@ public class LinkBuilder : ILinkBuilder
23
23
private const string PageSizeParameterName = "page[size]" ;
24
24
private const string PageNumberParameterName = "page[number]" ;
25
25
26
- private static readonly string GetPrimaryControllerAction = WithoutAsyncSuffix ( nameof ( BaseJsonApiController < Identifiable > . GetAsync ) ) ;
27
- private static readonly string GetSecondaryControllerAction = WithoutAsyncSuffix ( nameof ( BaseJsonApiController < Identifiable > . GetSecondaryAsync ) ) ;
28
- private static readonly string GetRelationshipControllerAction = WithoutAsyncSuffix ( nameof ( BaseJsonApiController < Identifiable > . GetRelationshipAsync ) ) ;
26
+ private static readonly string GetPrimaryControllerActionName = NoAsyncSuffix ( nameof ( BaseJsonApiController < Identifiable > . GetAsync ) ) ;
27
+ private static readonly string GetSecondaryControllerActionName = NoAsyncSuffix ( nameof ( BaseJsonApiController < Identifiable > . GetSecondaryAsync ) ) ;
28
+ private static readonly string GetRelationshipControllerActionName = NoAsyncSuffix ( nameof ( BaseJsonApiController < Identifiable > . GetRelationshipAsync ) ) ;
29
29
30
30
private readonly IJsonApiOptions _options ;
31
31
private readonly IJsonApiRequest _request ;
@@ -55,7 +55,7 @@ public LinkBuilder(IJsonApiOptions options, IJsonApiRequest request, IPagination
55
55
_controllerResourceMapping = controllerResourceMapping ;
56
56
}
57
57
58
- private static string WithoutAsyncSuffix ( string actionName )
58
+ private static string NoAsyncSuffix ( string actionName )
59
59
{
60
60
return actionName . EndsWith ( "Async" , StringComparison . Ordinal ) ? actionName [ ..^ "Async" . Length ] : actionName ;
61
61
}
@@ -185,6 +185,19 @@ private IList<PaginationElementQueryStringValueExpression> ParsePageSizeExpressi
185
185
}
186
186
187
187
private string GetLinkForPagination ( int pageOffset , string pageSizeValue )
188
+ {
189
+ string queryStringValue = GetQueryStringInPaginationLink ( pageOffset , pageSizeValue ) ;
190
+
191
+ var builder = new UriBuilder ( _httpContextAccessor . HttpContext . Request . GetEncodedUrl ( ) )
192
+ {
193
+ Query = queryStringValue
194
+ } ;
195
+
196
+ UriComponents components = _options . UseRelativeLinks ? UriComponents . PathAndQuery : UriComponents . AbsoluteUri ;
197
+ return builder . Uri . GetComponents ( components , UriFormat . SafeUnescaped ) ;
198
+ }
199
+
200
+ private string GetQueryStringInPaginationLink ( int pageOffset , string pageSizeValue )
188
201
{
189
202
IDictionary < string , string > parameters =
190
203
_httpContextAccessor . HttpContext . Request . Query . ToDictionary ( pair => pair . Key , pair => pair . Value . ToString ( ) ) ;
@@ -208,15 +221,7 @@ private string GetLinkForPagination(int pageOffset, string pageSizeValue)
208
221
}
209
222
210
223
string queryStringValue = QueryString . Create ( parameters ) . Value ;
211
- queryStringValue = DecodeSpecialCharacters ( queryStringValue ) ;
212
-
213
- var builder = new UriBuilder ( _httpContextAccessor . HttpContext . Request . GetEncodedUrl ( ) )
214
- {
215
- Query = queryStringValue
216
- } ;
217
-
218
- UriComponents components = _options . UseRelativeLinks ? UriComponents . PathAndQuery : UriComponents . AbsoluteUri ;
219
- return builder . Uri . GetComponents ( components , UriFormat . SafeUnescaped ) ;
224
+ return DecodeSpecialCharacters ( queryStringValue ) ;
220
225
}
221
226
222
227
private static string DecodeSpecialCharacters ( string uri )
@@ -260,7 +265,7 @@ private string GetLinkForResourceSelf(ResourceContext resourceContext, string re
260
265
string controllerName = _controllerResourceMapping . GetControllerNameForResourceType ( resourceContext . ResourceType ) ;
261
266
IDictionary < string , object > routeValues = GetRouteValues ( resourceId , null ) ;
262
267
263
- return RenderLinkForAction ( controllerName , GetPrimaryControllerAction , routeValues ) ;
268
+ return RenderLinkForAction ( controllerName , GetPrimaryControllerActionName , routeValues ) ;
264
269
}
265
270
266
271
/// <inheritdoc />
@@ -290,15 +295,15 @@ private string GetLinkForRelationshipSelf(string primaryId, RelationshipAttribut
290
295
string controllerName = _controllerResourceMapping . GetControllerNameForResourceType ( relationship . LeftType ) ;
291
296
IDictionary < string , object > routeValues = GetRouteValues ( primaryId , relationship . PublicName ) ;
292
297
293
- return RenderLinkForAction ( controllerName , GetRelationshipControllerAction , routeValues ) ;
298
+ return RenderLinkForAction ( controllerName , GetRelationshipControllerActionName , routeValues ) ;
294
299
}
295
300
296
301
private string GetLinkForRelationshipRelated ( string primaryId , RelationshipAttribute relationship )
297
302
{
298
303
string controllerName = _controllerResourceMapping . GetControllerNameForResourceType ( relationship . LeftType ) ;
299
304
IDictionary < string , object > routeValues = GetRouteValues ( primaryId , relationship . PublicName ) ;
300
305
301
- return RenderLinkForAction ( controllerName , GetSecondaryControllerAction , routeValues ) ;
306
+ return RenderLinkForAction ( controllerName , GetSecondaryControllerActionName , routeValues ) ;
302
307
}
303
308
304
309
private IDictionary < string , object > GetRouteValues ( string primaryId , string relationshipName )
0 commit comments