From 992cb3f5f11b738974b0502a63e5aba3d27c8ea8 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Tue, 4 Aug 2026 16:53:13 +0300 Subject: [PATCH] Treat INACTIVE user status filter as all non-ACTIVE accounts. Admin Inactive filter can return pending, deactivated, suspended, and any other non-active statuses in one query. Co-authored-by: Cursor --- db/query/user.sql | 12 +++++++++++- gen/db/user.sql.go | 12 +++++++++++- internal/web_server/handlers/user.go | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/db/query/user.sql b/db/query/user.sql index 2e365cae..1ce34b0d 100644 --- a/db/query/user.sql +++ b/db/query/user.sql @@ -222,7 +222,17 @@ SELECT FROM users WHERE (sqlc.narg('role')::TEXT IS NULL OR role = sqlc.narg('role')::TEXT) - AND (sqlc.narg('status')::TEXT IS NULL OR status = sqlc.narg('status')::TEXT) + AND ( + sqlc.narg('status')::TEXT IS NULL + OR ( + sqlc.narg('status')::TEXT = 'INACTIVE' + AND status <> 'ACTIVE' + ) + OR ( + sqlc.narg('status')::TEXT <> 'INACTIVE' + AND status = sqlc.narg('status')::TEXT + ) + ) AND (sqlc.narg('query')::TEXT IS NULL OR ( first_name ILIKE '%' || sqlc.narg('query')::TEXT || '%' OR last_name ILIKE '%' || sqlc.narg('query')::TEXT || '%' diff --git a/gen/db/user.sql.go b/gen/db/user.sql.go index 596fc8b9..a9768a44 100644 --- a/gen/db/user.sql.go +++ b/gen/db/user.sql.go @@ -524,7 +524,17 @@ SELECT FROM users WHERE ($1::TEXT IS NULL OR role = $1::TEXT) - AND ($2::TEXT IS NULL OR status = $2::TEXT) + AND ( + $2::TEXT IS NULL + OR ( + $2::TEXT = 'INACTIVE' + AND status <> 'ACTIVE' + ) + OR ( + $2::TEXT <> 'INACTIVE' + AND status = $2::TEXT + ) + ) AND ($3::TEXT IS NULL OR ( first_name ILIKE '%' || $3::TEXT || '%' OR last_name ILIKE '%' || $3::TEXT || '%' diff --git a/internal/web_server/handlers/user.go b/internal/web_server/handlers/user.go index ebd7e524..f6114c51 100644 --- a/internal/web_server/handlers/user.go +++ b/internal/web_server/handlers/user.go @@ -436,7 +436,7 @@ func (h *Handler) CheckUserPending(c *fiber.Ctx) error { // @Param page_size query int false "Page size" // @Param created_before query string false "Created before (RFC3339)" // @Param created_after query string false "Created after (RFC3339)" -// @Param status query string false "User account status filter (ACTIVE, PENDING, SUSPENDED, DEACTIVATED)" +// @Param status query string false "User account status filter (ACTIVE, PENDING, SUSPENDED, DEACTIVATED, or INACTIVE for all non-ACTIVE statuses)" // @Param country query string false "Country filter (case-insensitive match on stored value)" // @Param region query string false "Region filter (case-insensitive match on stored value)" // @Param subscription_status query string false "Derived subscription filter: ACTIVE, PENDING, or Unsubscribed (matches response subscription_status semantics)"