Skip to content

Commit

Permalink
Revert "Hotfix: Revert "Fix SemVerLevel propagation in Odata Next lin…
Browse files Browse the repository at this point in the history
…ks. (#5582)" (#5623)" (#5624)

This reverts commit 2425677.
  • Loading branch information
Scott Bommarito committed Mar 15, 2018
1 parent 2425677 commit a4dcd89
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/NuGetGallery/Controllers/ODataV2CuratedFeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private async Task<IHttpActionResult> GetCore(
.ToV2FeedPackageQuery(GetSiteRoot(), _configurationService.Features.FriendlyLicenses, semVerLevelKey);

return QueryResult(options, pagedQueryable, MaxPageSize, totalHits, (o, s, resultCount) =>
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { id }, o, s));
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { id }, o, s, semVerLevelKey));
}
}
catch (Exception ex)
Expand Down Expand Up @@ -299,7 +299,8 @@ public async Task<IHttpActionResult> Search(
resultCount,
new { searchTerm, targetFramework, includePrerelease },
o,
s);
s,
semVerLevelKey);
}
return null;
});
Expand Down
6 changes: 3 additions & 3 deletions src/NuGetGallery/Controllers/ODataV2FeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task<IHttpActionResult> Get(
semVerLevelKey);

return QueryResult(options, pagedQueryable, MaxPageSize, totalHits, (o, s, resultCount) =>
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, null, o, s));
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, null, o, s, semVerLevelKey));
}
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ private async Task<IHttpActionResult> GetCore(
semVerLevelKey);

return QueryResult(options, pagedQueryable, MaxPageSize, totalHits, (o, s, resultCount) =>
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { id }, o, s));
SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { id }, o, s, semVerLevelKey));
}
}
catch (Exception ex)
Expand Down Expand Up @@ -358,7 +358,7 @@ public async Task<IHttpActionResult> Search(
// Strip it of for backward compatibility.
if (o.Top == null || (resultCount.HasValue && o.Top.Value >= resultCount.Value))
{
return SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { searchTerm, targetFramework, includePrerelease }, o, s);
return SearchAdaptor.GetNextLink(Request.RequestUri, resultCount, new { searchTerm, targetFramework, includePrerelease }, o, s, semVerLevelKey);
}
return null;
});
Expand Down
12 changes: 11 additions & 1 deletion src/NuGetGallery/OData/SearchService/SearchAdaptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static bool TryReadSearchFilter(bool allVersionsInIndex, string url, boo
return true;
}

public static Uri GetNextLink(Uri currentRequestUri, long? totalResultCount, object queryParameters, ODataQueryOptions options, ODataQuerySettings settings)
public static Uri GetNextLink(Uri currentRequestUri, long? totalResultCount, object queryParameters, ODataQueryOptions options, ODataQuerySettings settings, int? semVerLevelKey = null)
{
if (!totalResultCount.HasValue || totalResultCount.Value <= MaxPageSize || totalResultCount.Value == 0)
{
Expand Down Expand Up @@ -374,6 +374,16 @@ public static Uri GetNextLink(Uri currentRequestUri, long? totalResultCount, obj
queryBuilder.Append("&");
}

if (semVerLevelKey != null)
{
if(semVerLevelKey == SemVerLevelKey.SemVer2)
{
queryBuilder.Append("semVerLevel=");
queryBuilder.Append(SemVerLevelKey.SemVerLevel2);
queryBuilder.Append("&");
}
}

var queryString = queryBuilder.ToString().TrimEnd('&');

var builder = new UriBuilder(currentRequestUri);
Expand Down
17 changes: 17 additions & 0 deletions tests/NuGetGallery.Facts/Services/SearchAdaptorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ public void GeneratesNextLinkForComplexUrl()
// Assert
Assert.Equal(new Uri("https://localhost:8081/api/v2/Search()?searchTerm='foo'&$orderby=Id&$skip=200&$top=1000"), nextLink);
}

[Fact]
public void GeneratesNextLinkForComplexUrlWithSemVerLevel2()
{
// Arrange
var requestUri = new Uri("https://localhost:8081/api/v2/Search()?searchTerm='foo'&$orderby=Id&$skip=100&$top=1000&semVerLevel=2.0.0");
var resultCount = 2000; // our result set contains 2000 elements

// Act
var nextLink = SearchAdaptor.GetNextLink(requestUri, resultCount, new { searchTerm = "foo" },
GetODataQueryOptionsForTest(requestUri),
GetODataQuerySettingsForTest(),
SemVerLevelKey.SemVer2);

// Assert
Assert.Equal(new Uri("https://localhost:8081/api/v2/Search()?searchTerm='foo'&$orderby=Id&$skip=200&$top=1000&semVerLevel=2.0.0"), nextLink);
}
}
}
}

0 comments on commit a4dcd89

Please sign in to comment.