Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
fixed some asc/desc sorting attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Turupawn committed Oct 30, 2019
1 parent f19e46e commit 7ecf46b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/code-samples/c/02_BrowseMods.c
Expand Up @@ -37,6 +37,7 @@ int main(void)
ModioFilterCreator filter;
modioInitFilter(&filter);
modioSetFilterLimit(&filter, 3);
modioSetFilterSort(&filter, "popular", false);

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

Expand Down
9 changes: 8 additions & 1 deletion src/c/creators/ModioFilterCreator.cpp
Expand Up @@ -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];
Expand Down

0 comments on commit 7ecf46b

Please sign in to comment.