fix(sync): состав сетов ездит на сервер — колонка set_groups, upsert, bootstrap; счётчик синка считает и обновления

This commit is contained in:
Иван Овчинников
2026-11-22 00:53:32 +03:00
parent d7b9d0fa2d
commit b72f5f8e36
6 changed files with 83 additions and 1 deletions
+9
View File
@@ -1,5 +1,7 @@
# backend/routers/bootstrap.py
import json
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session, joinedload
from sqlalchemy import or_
@@ -65,6 +67,12 @@ def get_bootstrap_data(
def serialize_workout(w):
wt_name = w.workout_type.name if w.workout_type else ""
client_name = w.client.full_name if w.client else None
try:
set_groups = json.loads(w.set_groups or "[]")
if not isinstance(set_groups, list):
set_groups = []
except Exception:
set_groups = []
return {
"id": w.id,
@@ -75,6 +83,7 @@ def get_bootstrap_data(
"start_time": w.start_time,
"end_time": w.end_time,
"notes": w.notes,
"set_groups": set_groups,
"synced": w.synced,
"created_at": w.created_at,
"updated_at": w.updated_at,
+8
View File
@@ -1,3 +1,4 @@
import json
import uuid
from datetime import datetime
from typing import Dict, Optional, Tuple
@@ -361,6 +362,10 @@ def sync_data(
existing.end_time = workout_data.end_time if workout_data.end_time is not None else existing.end_time
existing.notes = workout_data.notes if workout_data.notes is not None else existing.notes
existing.workout_type_id = resolve_workout_type_id(db, workout_data.workout_type_id)
if workout_data.set_groups is not None:
existing.set_groups = json.dumps(
[g.model_dump() for g in workout_data.set_groups], ensure_ascii=False
)
existing.synced = 1
existing.updated_at = timestamp
@@ -398,6 +403,9 @@ def sync_data(
start_time=workout_data.start_time,
end_time=workout_data.end_time,
notes=workout_data.notes or "",
set_groups=json.dumps(
[g.model_dump() for g in workout_data.set_groups or []], ensure_ascii=False
),
synced=1,
created_at=timestamp,
updated_at=timestamp,