Add events history

This commit is contained in:
2025-12-15 22:31:42 +07:00
parent 4239ea8516
commit 9a037cb34f
7 changed files with 801 additions and 231 deletions

View File

@@ -157,13 +157,16 @@ class EventService:
- winners_list: list of winners if event closed, None otherwise
"""
if event.type != EventType.COMMON_ENEMY.value:
print(f"[COMMON_ENEMY] Event type mismatch: {event.type}")
return 0, False, None
data = event.data or {}
completions = data.get("completions", [])
print(f"[COMMON_ENEMY] Current completions count: {len(completions)}")
# Check if already completed
if any(c["participant_id"] == participant_id for c in completions):
print(f"[COMMON_ENEMY] Participant {participant_id} already completed")
return 0, False, None
# Add completion
@@ -174,6 +177,7 @@ class EventService:
"completed_at": datetime.utcnow().isoformat(),
"rank": rank,
})
print(f"[COMMON_ENEMY] Added completion for user {user_id}, rank={rank}")
# Update event data - need to flag_modified for SQLAlchemy to detect JSON changes
event.data = {**data, "completions": completions}
@@ -189,6 +193,7 @@ class EventService:
event.end_time = datetime.utcnow()
event_closed = True
winners_list = completions[:3] # Top 3
print(f"[COMMON_ENEMY] Event auto-closed! Winners: {winners_list}")
await db.commit()