Skip to content

Badge Trigger System 4.3#26

Merged
Arhum2 merged 4 commits intomainfrom
sprint4/badge-trigger-system
Mar 20, 2026
Merged

Badge Trigger System 4.3#26
Arhum2 merged 4 commits intomainfrom
sprint4/badge-trigger-system

Conversation

@Sheep4545
Copy link
Collaborator

@Sheep4545 Sheep4545 commented Mar 17, 2026

  • 🎉 New feature (Extends application, non-breaking feature)

PR Summary

Implements backend badge trigger logic that evaluates user engagement stats against configured badge rules and automatically persists newly earned badges to public.user_badges without duplicating awards.

Overview

  • What feature/problem does this PR address?

Adds automatic badge awarding when users earn XP / progress streaks, so achievements are granted consistently and stored in the database.

  • What approach was taken?

Added a modular badge trigger service (backend/services/badge_trigger.py) with a registry of badge conditions keyed by badge slug.
Wired badge evaluation into existing gamification event flows after XP is applied (/api/v1/quiz/result, /api/v1/flashcards/session-complete).
Persisted awards to public.user_badges and prevented duplicates by checking existing awards and relying on the (user_id, badge_id) primary key.

  • Any important design decisions or trade-offs?

Badge rules are defined in a centralized registry for easy extension (new badge = DB row + new condition entry).
Awarding emits server logs on success for traceability.

Checklist

  • Added a clear description
  • Included evidence of Unit Testing: pytest (backend) passing: 146 passed
  • Updated domentation (if needed)

Additional Notes

Manual testing performed (sample events):
Triggered quiz completion XP and verified new badge grants persisted to public.user_badges (getting_started, first_xp, 50_xp).
Replayed the same event and confirmed no duplicate badge awards (new_badges=[]).
Triggered flashcard session XP and confirmed no unexpected additional badges.

Jira Ticket

Jira Ticket(s) - [SOC-23]

@Sheep4545 Sheep4545 requested a review from Arhum2 March 17, 2026 15:03
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@Arhum2 Arhum2 merged commit 39ed545 into main Mar 20, 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