add get day claim reward endpoint
This commit is contained in:
@ -158,3 +158,12 @@ async def claim_daily(accessToken: str = Query(...), clientToken: str = Query(..
|
|||||||
async def daily_status(accessToken: str = Query(...), clientToken: str = Query(...)):
|
async def daily_status(accessToken: str = Query(...), clientToken: str = Query(...)):
|
||||||
me = await AuthService().get_current_user(accessToken, clientToken)
|
me = await AuthService().get_current_user(accessToken, clientToken)
|
||||||
return await DailyRewardService().get_status(me["username"])
|
return await DailyRewardService().get_status(me["username"])
|
||||||
|
|
||||||
|
@router.get("/users/daily/days")
|
||||||
|
async def daily_days(
|
||||||
|
accessToken: str = Query(...),
|
||||||
|
clientToken: str = Query(...),
|
||||||
|
limit: int = Query(60, ge=1, le=365),
|
||||||
|
):
|
||||||
|
me = await AuthService().get_current_user(accessToken, clientToken)
|
||||||
|
return await DailyRewardService().get_claim_days(me["username"], limit=limit)
|
||||||
|
|||||||
@ -116,3 +116,29 @@ class DailyRewardService:
|
|||||||
"next_claim_at_local": (start_today_local + timedelta(days=1)).isoformat(),
|
"next_claim_at_local": (start_today_local + timedelta(days=1)).isoformat(),
|
||||||
"streak": int(user.get("daily_streak", 0) or 0),
|
"streak": int(user.get("daily_streak", 0) or 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async def get_claim_days(self, username: str, limit: int = 60) -> dict:
|
||||||
|
# Берём последние N записей daily_login и превращаем в список уникальных дней по ЕКБ
|
||||||
|
cursor = coins_sessions_collection.find(
|
||||||
|
{"player_name": username, "update_type": "daily_login"},
|
||||||
|
{"timestamp": 1, "_id": 0},
|
||||||
|
).sort("timestamp", -1).limit(limit)
|
||||||
|
|
||||||
|
days = []
|
||||||
|
seen = set()
|
||||||
|
|
||||||
|
async for doc in cursor:
|
||||||
|
ts = doc.get("timestamp")
|
||||||
|
if not ts:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# У тебя timestamp в Mongo — naive UTC (now_utc.replace(tzinfo=None)) :contentReference[oaicite:1]{index=1}
|
||||||
|
ts_utc = ts.replace(tzinfo=timezone.utc)
|
||||||
|
day_local = ts_utc.astimezone(TZ).date().isoformat() # YYYY-MM-DD по ЕКБ
|
||||||
|
|
||||||
|
if day_local not in seen:
|
||||||
|
seen.add(day_local)
|
||||||
|
days.append(day_local)
|
||||||
|
|
||||||
|
days.reverse() # чтобы было по возрастанию (старые → новые), если надо
|
||||||
|
return {"ok": True, "days": days, "count": len(days)}
|
||||||
Reference in New Issue
Block a user