Skip to content

feat: Add queries and accessors to fetch lead wise status#587

Open
manas-narra wants to merge 1 commit intojuspay:releasefrom
manas-narra:add-queries-to-fetch-lead-wise-data
Open

feat: Add queries and accessors to fetch lead wise status#587
manas-narra wants to merge 1 commit intojuspay:releasefrom
manas-narra:add-queries-to-fetch-lead-wise-data

Conversation

@manas-narra
Copy link
Collaborator

@manas-narra manas-narra commented Feb 23, 2026

  • Added queries and accessors to fetch lead wise status

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a new analytics metric for lead status counts that displays leads grouped by their status (backlog, processing, finished) and organized by merchant and shop identifier.
    • Included search and pagination capabilities to filter and navigate through lead status data efficiently.

@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

A new lead status counts analytics feature is introduced across multiple application layers. The implementation spans API routing, database accessors, query builders, and schema definitions, following existing handler patterns with pagination and search capabilities.

Changes

Cohort / File(s) Summary
API Routing & Handlers
app/api/routers/breeze_buddy/analytics/__init__.py, app/api/routers/breeze_buddy/analytics/handlers.py
New get_lead_status_counts handler added with pagination support (1-100 limit), admin/non-admin scoping, search filtering by merchant_id and shop_identifier, and result formatting. Handler is exported and routed via AnalyticsType.LEAD_STATUS_COUNTS. Note: handler function appears duplicated in handlers.py.
Database Layer
app/database/accessor/breeze_buddy/analytics.py, app/database/queries/breeze_buddy/analytics.py
Two query builders added: get_analytics_lead_status_counts_query (paginated, with search) and get_analytics_lead_status_counts_total_query (total count). New accessor get_lead_status_counts_from_db orchestrates query execution with pagination metadata and error handling.
Schemas & Models
app/schemas/breeze_buddy/analytics.py
New AnalyticsType.LEAD_STATUS_COUNTS enum variant added. New LeadStatusCountResult model with merchant_id, shop_identifier, and status count fields. AnalyticsResponse model expanded with success, data, and error fields.

Sequence Diagram

sequenceDiagram
    participant Client as API Client
    participant Handler as get_lead_status_counts Handler
    participant Accessor as Accessor Function
    participant Query as Query Builders
    participant DB as Database

    Client->>Handler: Request with filters, pagination options
    Handler->>Handler: Validate pagination bounds & apply user scoping
    Handler->>Accessor: Call get_lead_status_counts_from_db(filters, page, limit, search...)
    Accessor->>Query: Call get_analytics_lead_status_counts_query(...)
    Query->>Query: Build WHERE clause with search filters
    Query-->>Accessor: Return SQL + params
    Accessor->>DB: Execute paginated query
    DB-->>Accessor: Lead status counts rows
    Accessor->>Query: Call get_analytics_lead_status_counts_total_query(...)
    Query-->>Accessor: Return SQL + params for total count
    Accessor->>DB: Execute total count query
    DB-->>Accessor: Total count value
    Accessor->>Accessor: Compute total_pages, format results
    Accessor-->>Handler: Return structured response with pagination
    Handler->>Handler: Format final response
    Handler-->>Client: Return analytics with formatted results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Note: Review should pay special attention to the duplication of get_lead_status_counts in handlers.py, which requires clarification or consolidation.

Suggested reviewers

  • badri-singhal

Poem

🐰 With whiskers twitching, counts align,
Lead statuses in rows so fine!
From backlog hops to finished lines,
Analytics bloom—a feature divine! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main feature addition - new queries and accessors for fetching lead status information, which aligns with the substantial changes across the database layer.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/api/routers/breeze_buddy/analytics/handlers.py (1)

687-689: Redundant ternary for shop_identifier.

row.get("shop_identifier") if row.get("shop_identifier") else None is equivalent to row.get("shop_identifier") since dict.get already returns None by default when the key is missing, and a falsy value (empty string) is already mapped to None.

♻️ Simplification
-                "shop_identifier": (
-                    row.get("shop_identifier") if row.get("shop_identifier") else None
-                ),
+                "shop_identifier": row.get("shop_identifier") or None,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/api/routers/breeze_buddy/analytics/handlers.py` around lines 687 - 689,
The assignment for "shop_identifier" uses a redundant ternary; replace the
expression row.get("shop_identifier") if row.get("shop_identifier") else None
with a direct row.get("shop_identifier") in the code that builds the row mapping
(the dict construction around "shop_identifier" in handlers.py), so the value is
the same but simpler and clearer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/database/queries/breeze_buddy/analytics.py`:
- Around line 748-756: Add a helper function _escape_ilike(value: str) that
escapes backslashes, % and _ (replace "\" -> "\\", "%" -> "\%", "_" -> "\_"),
then use it when building ILIKE parameters for search_merchant_id and
search_shop_identifier (replace values.append(f"%{...}%") with
values.append(f"%{_escape_ilike(...)}%")); also apply the same change in the
total-count query where those parameters are added, and ensure the ILIKE
expressions include an explicit ESCAPE '\\' clause so the escaped characters are
treated literally.

---

Nitpick comments:
In `@app/api/routers/breeze_buddy/analytics/handlers.py`:
- Around line 687-689: The assignment for "shop_identifier" uses a redundant
ternary; replace the expression row.get("shop_identifier") if
row.get("shop_identifier") else None with a direct row.get("shop_identifier") in
the code that builds the row mapping (the dict construction around
"shop_identifier" in handlers.py), so the value is the same but simpler and
clearer.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 614bb8f and a9a2724.

📒 Files selected for processing (5)
  • app/api/routers/breeze_buddy/analytics/__init__.py
  • app/api/routers/breeze_buddy/analytics/handlers.py
  • app/database/accessor/breeze_buddy/analytics.py
  • app/database/queries/breeze_buddy/analytics.py
  • app/schemas/breeze_buddy/analytics.py

  - Added queries and accessors to fetch lead wise status
@manas-narra manas-narra force-pushed the add-queries-to-fetch-lead-wise-data branch from a9a2724 to 6c1266a Compare February 24, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant