Add dispute system
This commit is contained in:
@@ -60,6 +60,39 @@ async def get_active_assignment(db, participant_id: int, is_event: bool = False)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_oldest_returned_assignment(db, participant_id: int) -> Assignment | None:
|
||||
"""Get the oldest returned assignment that needs to be redone."""
|
||||
result = await db.execute(
|
||||
select(Assignment)
|
||||
.options(
|
||||
selectinload(Assignment.challenge).selectinload(Challenge.game)
|
||||
)
|
||||
.where(
|
||||
Assignment.participant_id == participant_id,
|
||||
Assignment.status == AssignmentStatus.RETURNED.value,
|
||||
Assignment.is_event_assignment == False,
|
||||
)
|
||||
.order_by(Assignment.completed_at.asc()) # Oldest first
|
||||
.limit(1)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def activate_returned_assignment(db, returned_assignment: Assignment) -> None:
|
||||
"""
|
||||
Re-activate a returned assignment.
|
||||
Simply changes the status back to ACTIVE.
|
||||
"""
|
||||
returned_assignment.status = AssignmentStatus.ACTIVE.value
|
||||
returned_assignment.started_at = datetime.utcnow()
|
||||
# Clear previous proof data for fresh attempt
|
||||
returned_assignment.proof_path = None
|
||||
returned_assignment.proof_url = None
|
||||
returned_assignment.proof_comment = None
|
||||
returned_assignment.completed_at = None
|
||||
returned_assignment.points_earned = 0
|
||||
|
||||
|
||||
@router.post("/marathons/{marathon_id}/spin", response_model=SpinResult)
|
||||
async def spin_wheel(marathon_id: int, current_user: CurrentUser, db: DbSession):
|
||||
"""Spin the wheel to get a random game and challenge"""
|
||||
@@ -347,6 +380,7 @@ async def complete_assignment(
|
||||
|
||||
# Log activity
|
||||
activity_data = {
|
||||
"assignment_id": assignment.id,
|
||||
"game": full_challenge.game.title,
|
||||
"challenge": challenge.title,
|
||||
"difficulty": challenge.difficulty,
|
||||
@@ -407,6 +441,13 @@ async def complete_assignment(
|
||||
|
||||
await db.commit()
|
||||
|
||||
# Check for returned assignments and activate the oldest one
|
||||
returned_assignment = await get_oldest_returned_assignment(db, participant.id)
|
||||
if returned_assignment:
|
||||
await activate_returned_assignment(db, returned_assignment)
|
||||
await db.commit()
|
||||
print(f"[WHEEL] Auto-activated returned assignment {returned_assignment.id} for participant {participant.id}")
|
||||
|
||||
return CompleteResult(
|
||||
points_earned=total_points,
|
||||
streak_bonus=streak_bonus,
|
||||
|
||||
Reference in New Issue
Block a user