aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/auth/authorisation/resources/groups/views.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-07-08 04:49:32 -0500
committerFrederick Muriuki Muriithi2025-07-08 04:49:32 -0500
commit26671875ec631c08049631263e37df1f61e95953 (patch)
treeed483807bf58b8ac918819e773069332d3d4fd50 /gn_auth/auth/authorisation/resources/groups/views.py
parent9e130a93838091bb0f23484193045744a354393e (diff)
downloadgn-auth-26671875ec631c08049631263e37df1f61e95953.tar.gz
Enable filtering of groups list and length limiting.
Diffstat (limited to 'gn_auth/auth/authorisation/resources/groups/views.py')
-rw-r--r--gn_auth/auth/authorisation/resources/groups/views.py32
1 files changed, 10 insertions, 22 deletions
diff --git a/gn_auth/auth/authorisation/resources/groups/views.py b/gn_auth/auth/authorisation/resources/groups/views.py
index 0c1fefd..1e95f09 100644
--- a/gn_auth/auth/authorisation/resources/groups/views.py
+++ b/gn_auth/auth/authorisation/resources/groups/views.py
@@ -36,33 +36,21 @@ groups = Blueprint("groups", __name__)
def list_groups():
"""Return the list of groups that exist."""
_kwargs = {key: value for key, value in request_json().items()}
- _total = 0
- _start = int(_kwargs.get("start", "0"))
- _length = int(_kwargs.get("length", "0"))
- def __add_total_group_count__(conn, groups_list):
- with db.cursor(conn) as cursor:
- cursor.execute("SELECT COUNT(*) FROM groups")
- _total = int(cursor.fetchone()["COUNT(*)"])
-
- return {
- "total-groups": _total,
- "groups": groups_list
- }
-
- def __slice__(groups_details):
- _groups = groups_details["groups"]
+ def __add_total_group_count__(conn, groups_info):
return {
- **groups_details,
- "total-filtered": len(_groups),
- "groups": _groups[
- _start:_start+(_length if bool(_length) else len(_groups))]
+ "groups": groups_info[0],
+ "total-groups": groups_info[1],
+ "total-filtered": groups_info[2]
}
with db.connection(current_app.config["AUTH_DB"]) as conn:
- return jsonify(all_groups(conn).then(
- partial(__add_total_group_count__, conn)
+ return jsonify(all_groups(
+ conn,
+ search=_kwargs.get("search"),
+ start=int(_kwargs.get("start", "0")),
+ length=int(_kwargs.get("length", "0"))
).then(
- __slice__
+ partial(__add_total_group_count__, conn)
).maybe(
{
"groups": [],