...
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// lib/features/gamification/models/gamification_models.dart
|
||||
// Data models matching TechDocs v2 DB schema for the Contributor Module.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tier enum — matches PRD v3 §4.4 thresholds (based on Lifetime EP)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -68,13 +70,21 @@ int tierStartEp(ContributorTier tier) {
|
||||
// ---------------------------------------------------------------------------
|
||||
class UserGamificationProfile {
|
||||
final String userId;
|
||||
final int lifetimeEp; // Never resets. Used for tiers + leaderboard.
|
||||
final int currentEp; // Liquid EP accumulated this month.
|
||||
final int currentRp; // Spendable Reward Points.
|
||||
final String username;
|
||||
final String? avatarUrl;
|
||||
final String? district;
|
||||
final String? eventifyId;
|
||||
final int lifetimeEp; // Never resets. Used for tiers + leaderboard.
|
||||
final int currentEp; // Liquid EP accumulated this month.
|
||||
final int currentRp; // Spendable Reward Points.
|
||||
final ContributorTier tier;
|
||||
|
||||
const UserGamificationProfile({
|
||||
required this.userId,
|
||||
required this.username,
|
||||
this.avatarUrl,
|
||||
this.district,
|
||||
this.eventifyId,
|
||||
required this.lifetimeEp,
|
||||
required this.currentEp,
|
||||
required this.currentRp,
|
||||
@@ -82,12 +92,17 @@ class UserGamificationProfile {
|
||||
});
|
||||
|
||||
factory UserGamificationProfile.fromJson(Map<String, dynamic> json) {
|
||||
final ep = (json['lifetime_ep'] as int?) ?? 0;
|
||||
debugPrint('Mapping UserGamificationProfile from JSON: $json');
|
||||
final ep = (json['lifetime_ep'] as int?) ?? (json['points'] as int?) ?? (json['total_points'] as int?) ?? 0;
|
||||
return UserGamificationProfile(
|
||||
userId: json['user_id'] as String? ?? '',
|
||||
userId: (json['user_id'] ?? json['email'] ?? json['userId'] ?? '').toString(),
|
||||
username: (json['username'] ?? json['name'] ?? json['full_name'] ?? json['display_name'] ?? '').toString(),
|
||||
avatarUrl: json['profile_image'] as String? ?? json['avatar_url'] as String? ?? json['profile_pic'] as String?,
|
||||
district: json['district'] as String? ?? json['location'] as String?,
|
||||
eventifyId: (json['eventify_id'] ?? json['eventifyId'] ?? json['id'] ?? '').toString(),
|
||||
lifetimeEp: ep,
|
||||
currentEp: (json['current_ep'] as int?) ?? 0,
|
||||
currentRp: (json['current_rp'] as int?) ?? 0,
|
||||
currentEp: (json['current_ep'] as int?) ?? (json['monthly_points'] as int?) ?? (json['points_this_month'] as int?) ?? 0,
|
||||
currentRp: (json['current_rp'] as int?) ?? (json['reward_points'] as int?) ?? (json['rp'] as int?) ?? 0,
|
||||
tier: tierFromEp(ep),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user