Skip to content

Fix college sorting bug and add IG task summary API#2673

Closed
NayanUnni95 wants to merge 3 commits into
gtech-mulearn:devfrom
NayanUnni95:intern/task
Closed

Fix college sorting bug and add IG task summary API#2673
NayanUnni95 wants to merge 3 commits into
gtech-mulearn:devfrom
NayanUnni95:intern/task

Conversation

@NayanUnni95

@NayanUnni95 NayanUnni95 commented Mar 17, 2026

Copy link
Copy Markdown
Member

Task1 #2651 — Fix Sorting Bug + Add Multi-Field Sorting

Fix Implemented

Updated the sort_fields dictionary in CollegeApi.get() to correctly map query params to ORM fields

sort_fields = {
    "org": "org__title",
    "level": "level",
    "created_at": "created_at"
}

Verification

Tested using Postman:

  • sortBy=level → ascending
  • sortBy=-level →descending
  • sortBy=created_at → oldest first
  • sortBy=-created_at → newest first

Also verified:

  • Pagination (pageIndex, perPage) works correctly
  • Search (?search=) is unaffected
  • Unsupported sortBy values fall back gracefully

Edge Cases Considered

  • Invalid sortBy → no crash, default behavior preserved
  • Null or missing related org → handled safely by ORM

Postman screenshots

Screenshot from 2026-03-18 00-05-50 Screenshot from 2026-03-18 00-06-00 Screenshot from 2026-03-18 00-06-09 Screenshot from 2026-03-18 00-06-22 Screenshot from 2026-03-18 00-06-43

Task2 #2658 — IG Task Summary API

Endpoint Added

GET /api/v1/dashboard/ig/<ig_id>/task-summary/

Implementation Approach

  • Added IGTaskSummaryAPI in dash_ig_view.py
  • Used ORM aggregation (Count, Sum) on KarmaActivityLog
  • Applied optional date filtering (from_date, to_date)
  • No N+1 queries (fully DB-level aggregation)

Features Implemented

  • Returns:
    • Total tasks completed
    • Total karma awarded
    • Unique contributors
    • Top 5 contributors
  • Supports optional date range filtering
  • Returns zero values if no activity exists
  • Proper error handling for:
    • Invalid ig_id
    • Invalid date format

Tested via Postman:

summary-correct-date summary-incorrect-date

Assumptions:

  • KarmaActivityLog represents completed task activity
  • karma field is used for aggregation
  • created_at is used for date filtering

Checklist

  • Fixed sortBy=org bug
  • Added multi-field sorting support
  • Implemented IG Task Summary API
  • Date filtering works correctly
  • Returns zeros when no activity exists
  • Proper error handling implemented
  • No N+1 queries (DB-level aggregation used)
  • Follows project coding conventions

@awindsr awindsr closed this Jun 22, 2026
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.

2 participants