You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
927 B
34 lines
927 B
using System;
|
|
namespace OpenLibraryClient
|
|
{
|
|
public static class RouteExtensions
|
|
{
|
|
public static string AddPagination(this string route, int index, int count)
|
|
{
|
|
if(index <= -1 || count<0)
|
|
{
|
|
return route;
|
|
}
|
|
string delimiter = route.Contains("?") ? "&" : "?";
|
|
return $"{route}{delimiter}limit={count}&page={index+1}";
|
|
}
|
|
|
|
public static string AddSort(this string route, string sort)
|
|
{
|
|
string sortCriterium = sort switch
|
|
{
|
|
"new" => "new",
|
|
"old" => "old",
|
|
"random" => "random",
|
|
"key" => "key",
|
|
_ => null
|
|
};
|
|
if(sortCriterium == null) return route;
|
|
|
|
string delimiter = route.Contains("?") ? "&" : "?";
|
|
return $"{route}{delimiter}sort={sortCriterium}";
|
|
}
|
|
}
|
|
}
|
|
|