Skip to content
Permalink
Browse files

fixed some asc/desc sorting attributes

  • Loading branch information
Turupawn committed Oct 30, 2019
1 parent f19e46e commit 7ecf46b98bfa3013d7bfb34600be74c3b4ccbe24
Showing with 9 additions and 1 deletion.
  1. +1 −0 examples/code-samples/c/02_BrowseMods.c
  2. +8 −1 src/c/creators/ModioFilterCreator.cpp
@@ -37,6 +37,7 @@ int main(void)
ModioFilterCreator filter;
modioInitFilter(&filter);
modioSetFilterLimit(&filter, 3);
modioSetFilterSort(&filter, "popular", false);

printf("Getting mods...\n");

@@ -74,12 +74,19 @@ extern "C"
filter->cache_max_age_seconds = 1;
}

bool shouldAppendMinusToSort(std::string field, bool ascending)
{
if(field == "popular" || field == "downloads" || field == "rating" || field == "subscribers")
return ascending;
return !ascending;
}

void modioSetFilterSort(ModioFilterCreator* filter, char const* field, bool ascending)
{
if(filter->sort)
delete[] filter->sort;
std::string ascending_str = "";
if(!ascending)
if(shouldAppendMinusToSort(field, ascending))
ascending_str = "-";
std::string sort_str = std::string("_sort=") + ascending_str + field;
filter->sort = new char[sort_str.size() + 1];

0 comments on commit 7ecf46b

Please sign in to comment.
You can’t perform that action at this time.