/api/user/summary: streak.activeToday and streak.lost for the app's lit / at-risk / frozen flame
activeToday: activity recorded today (Tehran date). lost: length of a streak that broke (last active day before yesterday), so the app can show it frozen. Same rule as effective_current_streak; the weekly report keeps its own two-field streak serializer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ from rest_framework.throttling import ScopedRateThrottle
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from .models import Character, StreakRecord, UserHearts, UserStats
|
||||
from .services import effective_current_streak
|
||||
from .services import effective_current_streak, streak_state
|
||||
from .serializers import (
|
||||
CharacterListResponseSerializer,
|
||||
LeaderboardResponseSerializer,
|
||||
@@ -47,6 +47,7 @@ class UserSummaryView(APIView):
|
||||
user = request.user # accounts.User، از طریق TadrisinoTokenAuthentication
|
||||
stats = UserStats.objects.filter(user_id=user.id).first()
|
||||
streak = StreakRecord.objects.filter(user_id=user.id).first()
|
||||
current, active_today, lost = streak_state(streak)
|
||||
|
||||
data = {
|
||||
'userId': str(user.id),
|
||||
@@ -56,8 +57,10 @@ class UserSummaryView(APIView):
|
||||
'xp': stats.xp if stats else 0,
|
||||
'coins': stats.coins if stats else 0,
|
||||
'streak': {
|
||||
'current': effective_current_streak(streak),
|
||||
'current': current,
|
||||
'longest': streak.longest_streak if streak else 0,
|
||||
'activeToday': active_today,
|
||||
'lost': lost,
|
||||
},
|
||||
# عنوانِ پلنِ اشتراکِ فعال، یا null. تا ۲۰۲۶-۰۹-۲۴ همیشه null بود
|
||||
# (از زمانی که اپِ subscription هنوز وجود نداشت).
|
||||
|
||||
Reference in New Issue
Block a user