Time tracker app
This commit is contained in:
@@ -15,6 +15,7 @@ from app.models import (
|
||||
from app.schemas import (
|
||||
SpinResult, AssignmentResponse, CompleteResult, DropResult,
|
||||
GameResponse, ChallengeResponse, GameShort, UserPublic, MessageResponse,
|
||||
TrackTimeRequest,
|
||||
)
|
||||
from app.schemas.game import PlaythroughInfo
|
||||
from app.services.points import PointsService
|
||||
@@ -589,7 +590,14 @@ async def complete_assignment(
|
||||
if assignment.is_playthrough:
|
||||
game = assignment.game
|
||||
marathon_id = game.marathon_id
|
||||
base_playthrough_points = game.playthrough_points
|
||||
|
||||
# If tracked time exists (from desktop app), calculate points as hours * 30
|
||||
# Otherwise use admin-set playthrough_points
|
||||
if assignment.tracked_time_minutes > 0:
|
||||
hours = assignment.tracked_time_minutes / 60
|
||||
base_playthrough_points = int(hours * 30)
|
||||
else:
|
||||
base_playthrough_points = game.playthrough_points
|
||||
|
||||
# Calculate BASE bonus points from completed bonus assignments (before multiplier)
|
||||
base_bonus_points = sum(
|
||||
@@ -850,6 +858,37 @@ async def complete_assignment(
|
||||
)
|
||||
|
||||
|
||||
@router.patch("/assignments/{assignment_id}/track-time", response_model=MessageResponse)
|
||||
async def track_assignment_time(
|
||||
assignment_id: int,
|
||||
data: TrackTimeRequest,
|
||||
current_user: CurrentUser,
|
||||
db: DbSession,
|
||||
):
|
||||
"""Update tracked time for an assignment (from desktop app)"""
|
||||
result = await db.execute(
|
||||
select(Assignment)
|
||||
.options(selectinload(Assignment.participant))
|
||||
.where(Assignment.id == assignment_id)
|
||||
)
|
||||
assignment = result.scalar_one_or_none()
|
||||
|
||||
if not assignment:
|
||||
raise HTTPException(status_code=404, detail="Assignment not found")
|
||||
|
||||
if assignment.participant.user_id != current_user.id:
|
||||
raise HTTPException(status_code=403, detail="This is not your assignment")
|
||||
|
||||
if assignment.status != AssignmentStatus.ACTIVE.value:
|
||||
raise HTTPException(status_code=400, detail="Assignment is not active")
|
||||
|
||||
# Update tracked time (replace with new value)
|
||||
assignment.tracked_time_minutes = max(0, data.minutes)
|
||||
await db.commit()
|
||||
|
||||
return MessageResponse(message=f"Tracked time updated to {data.minutes} minutes")
|
||||
|
||||
|
||||
@router.post("/assignments/{assignment_id}/drop", response_model=DropResult)
|
||||
async def drop_assignment(assignment_id: int, current_user: CurrentUser, db: DbSession):
|
||||
"""Drop current assignment"""
|
||||
|
||||
Reference in New Issue
Block a user