Fix duplicate detection, add wellness suffixes, add reprocess endpoint
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, func, desc
|
||||
from sqlalchemy import select, func, desc, delete
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
@@ -126,7 +126,6 @@ async def get_data_points(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
# Verify ownership
|
||||
act = await db.execute(
|
||||
select(Activity).where(
|
||||
Activity.id == activity_id,
|
||||
@@ -211,3 +210,38 @@ async def delete_activity(
|
||||
raise HTTPException(status_code=404, detail="Activity not found")
|
||||
await db.delete(activity)
|
||||
await db.commit()
|
||||
|
||||
|
||||
@router.post("/{activity_id}/reprocess")
|
||||
async def reprocess_activity(
|
||||
activity_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Re-parse the source FIT file and update polyline, data points etc."""
|
||||
import os
|
||||
result = await db.execute(
|
||||
select(Activity).where(
|
||||
Activity.id == activity_id,
|
||||
Activity.user_id == current_user.id,
|
||||
)
|
||||
)
|
||||
activity = result.scalar_one_or_none()
|
||||
if not activity:
|
||||
raise HTTPException(status_code=404, detail="Activity not found")
|
||||
if not activity.source_file:
|
||||
raise HTTPException(status_code=400, detail="No source file stored for this activity")
|
||||
if not os.path.exists(activity.source_file):
|
||||
raise HTTPException(status_code=404, detail="Source file no longer exists on disk")
|
||||
|
||||
source_file = activity.source_file
|
||||
source_type = activity.source_type or "fit"
|
||||
|
||||
await db.execute(delete(ActivityDataPoint).where(ActivityDataPoint.activity_id == activity_id))
|
||||
await db.execute(delete(ActivityLap).where(ActivityLap.activity_id == activity_id))
|
||||
await db.delete(activity)
|
||||
await db.commit()
|
||||
|
||||
from app.workers.tasks import process_activity_file
|
||||
task = process_activity_file.delay(source_file, current_user.id, source_type)
|
||||
return {"task_id": task.id, "status": "queued"}
|
||||
Reference in New Issue
Block a user