feat: rename activities; keep original Garmin title as a tag
Add Activity.original_name (migrated via init_db ALTER). The rename endpoint stores the import title the first time a user renames and clears it if renamed back. Activity detail page gets inline rename (pencil) UI and shows the original title beneath the new name; the activities list shows it as a small tag too. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ router = APIRouter()
|
||||
class ActivitySummary(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
original_name: Optional[str] = None
|
||||
sport_type: str
|
||||
start_time: datetime
|
||||
distance_m: Optional[float]
|
||||
@@ -368,9 +369,23 @@ async def rename_activity(
|
||||
if not activity:
|
||||
raise HTTPException(status_code=404, detail="Activity not found")
|
||||
|
||||
activity.name = body.get("name", activity.name)
|
||||
new_name = (body.get("name") or "").strip()
|
||||
if not new_name:
|
||||
raise HTTPException(status_code=400, detail="Name cannot be empty")
|
||||
|
||||
# Preserve the original import title the first time the user renames, so the
|
||||
# UI can still show it as a tag. Subsequent renames keep that same original.
|
||||
if activity.original_name is None and new_name != activity.name:
|
||||
activity.original_name = activity.name
|
||||
|
||||
activity.name = new_name
|
||||
|
||||
# If the user renames back to the original title, drop the tag.
|
||||
if activity.original_name == activity.name:
|
||||
activity.original_name = None
|
||||
|
||||
await db.commit()
|
||||
return {"id": activity_id, "name": activity.name}
|
||||
return {"id": activity_id, "name": activity.name, "original_name": activity.original_name}
|
||||
|
||||
|
||||
@router.delete("/{activity_id}", status_code=204)
|
||||
|
||||
@@ -56,6 +56,9 @@ async def init_db():
|
||||
await conn.execute(text(
|
||||
"ALTER TABLE activities ADD COLUMN IF NOT EXISTS moving_time_s FLOAT"
|
||||
))
|
||||
await conn.execute(text(
|
||||
"ALTER TABLE activities ADD COLUMN IF NOT EXISTS original_name VARCHAR(256)"
|
||||
))
|
||||
except Exception as e:
|
||||
print(f"activities.moving_time_s column migration skipped: {e}")
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ class Activity(Base):
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
|
||||
name = Column(String(256), nullable=False)
|
||||
original_name = Column(String(256), nullable=True) # Garmin/import title, kept when user renames
|
||||
sport_type = Column(String(64), nullable=False)
|
||||
start_time = Column(DateTime(timezone=True), nullable=False, index=True)
|
||||
end_time = Column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
Reference in New Issue
Block a user