Skip to content

Commit

Permalink
Added column sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
crisingulani committed Dec 11, 2024
1 parent 3eceebe commit ec309dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/pzserver/communicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,24 @@ def get_entities(self) -> list:

return list(resp.keys())

def get_all(self, entity) -> list:
def get_all(self, entity, ordering=None) -> list:
"""
Returns a list with all records of the entity.
Args:
entity (str): entity name e.g. "releases", "products", "product-types"
ordering (None or str): column name to be ordered
Returns:
list: list of records
"""

resp = self._get_request(f"{self._base_api_url}{entity}/")
uri = f"{self._base_api_url}{entity}/"

if ordering:
uri += f"?ordering={ordering}"

resp = self._get_request(uri)

if "success" in resp and resp["success"] is False:
raise requests.exceptions.RequestException(resp["message"])
Expand Down
2 changes: 1 addition & 1 deletion src/pzserver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_product_types(self) -> list:
Returns:
product types list
"""
return self.api.get_all("product-types")
return self.api.get_all("product-types", ordering="order")

def display_product_types(self):
"""
Expand Down

0 comments on commit ec309dc

Please sign in to comment.