Skip to content

Commit

Permalink
feat: apply filters/sorting by initial order
Browse files Browse the repository at this point in the history
  • Loading branch information
klen committed Oct 17, 2023
1 parent 6872de3 commit 0205c6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions muffin_rest/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ async def apply(
data = json_loads(raw_data)
assert isinstance(data, dict)
mutations = self.mutations
for name in data:
if name in mutations:
for name in mutations:
if name in data:
ops, collection = await mutations[name].apply(collection, data)
filters[name] = ops

Expand Down
9 changes: 5 additions & 4 deletions muffin_rest/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ async def apply(self, collection, *, desc: bool = False) -> Any:


class Sorting(Mutator):

"""Build sorters for handlers."""

MUTATE_CLASS = Sort
Expand All @@ -54,9 +53,11 @@ async def apply(
sorting = {}
if data:
collection = self.prepare(collection)
for name, desc in to_sort(data.split(",")):
sort = self.mutations.get(name)
if sort:
sorting = dict(to_sort(data.split(",")))
for name in self.mutations:
sort = self.mutations[name]
if name in sorting:
desc = sorting[name]
collection = await sort.apply(collection, desc=desc)
sorting[sort.name] = desc

Expand Down

0 comments on commit 0205c6d

Please sign in to comment.