6.27.1: Fitbit не меняет auto_complete в драфтах
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12997,22 +12997,12 @@ func (a *App) syncFitbitData(userID int, date time.Time) error {
|
||||
if err := a.saveFitbitSubtaskDraft(userID, int(stepsGoalTaskID.Int64), int(stepsGoalSubtaskID.Int64), goalReached); err != nil {
|
||||
log.Printf("Error saving steps goal subtask draft: %v", err)
|
||||
}
|
||||
} else if stepsGoalTaskID.Valid {
|
||||
goalReached := steps >= goalSteps
|
||||
if err := a.setFitbitTaskDraftAutoComplete(userID, int(stepsGoalTaskID.Int64), goalReached); err != nil {
|
||||
log.Printf("Error setting steps goal task draft auto_complete: %v", err)
|
||||
}
|
||||
}
|
||||
if floorsGoalTaskID.Valid && floorsGoalSubtaskID.Valid {
|
||||
goalReached := floors >= goalFloors
|
||||
if err := a.saveFitbitSubtaskDraft(userID, int(floorsGoalTaskID.Int64), int(floorsGoalSubtaskID.Int64), goalReached); err != nil {
|
||||
log.Printf("Error saving floors goal subtask draft: %v", err)
|
||||
}
|
||||
} else if floorsGoalTaskID.Valid {
|
||||
goalReached := floors >= goalFloors
|
||||
if err := a.setFitbitTaskDraftAutoComplete(userID, int(floorsGoalTaskID.Int64), goalReached); err != nil {
|
||||
log.Printf("Error setting floors goal task draft auto_complete: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Fitbit data synced for user_id=%d, date=%s: steps=%d, floors=%d, goalSteps=%d, goalFloors=%d",
|
||||
@@ -13022,7 +13012,7 @@ func (a *App) syncFitbitData(userID int, date time.Time) error {
|
||||
}
|
||||
|
||||
// saveFitbitProgressDraft сохраняет драфт задачи с прогрессом
|
||||
// Устанавливает progression_value и auto_complete = true
|
||||
// Устанавливает только progression_value, не меняет auto_complete
|
||||
func (a *App) saveFitbitProgressDraft(userID int, taskID int, progressionValue float64) error {
|
||||
var exists bool
|
||||
err := a.DB.QueryRow(`
|
||||
@@ -13037,13 +13027,13 @@ func (a *App) saveFitbitProgressDraft(userID int, taskID int, progressionValue f
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
_, err = a.DB.Exec(`
|
||||
INSERT INTO task_drafts (task_id, user_id, progression_value, auto_complete, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, TRUE, NOW(), NOW())
|
||||
INSERT INTO task_drafts (task_id, user_id, progression_value, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, NOW(), NOW())
|
||||
`, taskID, userID, progressionValue)
|
||||
} else if err == nil {
|
||||
_, err = a.DB.Exec(`
|
||||
UPDATE task_drafts
|
||||
SET progression_value = $1, auto_complete = TRUE, updated_at = NOW()
|
||||
SET progression_value = $1, updated_at = NOW()
|
||||
WHERE id = $2
|
||||
`, progressionValue, draftID)
|
||||
}
|
||||
@@ -13087,8 +13077,8 @@ func (a *App) saveFitbitSubtaskDraft(userID int, taskID int, subtaskID int, chec
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
err = tx.QueryRow(`
|
||||
INSERT INTO task_drafts (task_id, user_id, auto_complete, created_at, updated_at)
|
||||
VALUES ($1, $2, TRUE, NOW(), NOW())
|
||||
INSERT INTO task_drafts (task_id, user_id, created_at, updated_at)
|
||||
VALUES ($1, $2, NOW(), NOW())
|
||||
RETURNING id
|
||||
`, taskID, userID).Scan(&draftID)
|
||||
if err != nil {
|
||||
@@ -13096,13 +13086,6 @@ func (a *App) saveFitbitSubtaskDraft(userID int, taskID int, subtaskID int, chec
|
||||
}
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("failed to check draft: %w", err)
|
||||
} else {
|
||||
_, err = tx.Exec(`
|
||||
UPDATE task_drafts SET auto_complete = TRUE, updated_at = NOW() WHERE id = $1
|
||||
`, draftID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update draft: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if checked {
|
||||
@@ -13130,50 +13113,6 @@ func (a *App) saveFitbitSubtaskDraft(userID int, taskID int, subtaskID int, chec
|
||||
return nil
|
||||
}
|
||||
|
||||
// setFitbitTaskDraftAutoComplete создаёт или обновляет драфт задачи, выставляя только флаг «Выполнить в конце дня».
|
||||
// Используется для достижения цели по шагам/этажам, когда выбрана задача без подзадачи.
|
||||
func (a *App) setFitbitTaskDraftAutoComplete(userID int, taskID int, autoComplete bool) error {
|
||||
var exists bool
|
||||
err := a.DB.QueryRow(`
|
||||
SELECT EXISTS(SELECT 1 FROM tasks WHERE id = $1 AND user_id = $2 AND deleted = FALSE)
|
||||
`, taskID, userID).Scan(&exists)
|
||||
if err != nil || !exists {
|
||||
return fmt.Errorf("task %d not found or not owned by user", taskID)
|
||||
}
|
||||
|
||||
var draftID int
|
||||
err = a.DB.QueryRow("SELECT id FROM task_drafts WHERE task_id = $1", taskID).Scan(&draftID)
|
||||
if err == sql.ErrNoRows {
|
||||
if !autoComplete {
|
||||
return nil
|
||||
}
|
||||
_, err = a.DB.Exec(`
|
||||
INSERT INTO task_drafts (task_id, user_id, auto_complete, created_at, updated_at)
|
||||
VALUES ($1, $2, TRUE, NOW(), NOW())
|
||||
`, taskID, userID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create draft: %w", err)
|
||||
}
|
||||
log.Printf("Fitbit: created task draft for task_id=%d, auto_complete=true", taskID)
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get draft: %w", err)
|
||||
}
|
||||
|
||||
_, err = a.DB.Exec(`
|
||||
UPDATE task_drafts SET auto_complete = $1, updated_at = NOW() WHERE id = $2
|
||||
`, autoComplete, draftID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update draft: %w", err)
|
||||
}
|
||||
if !autoComplete {
|
||||
_, _ = a.DB.Exec("DELETE FROM task_draft_subtasks WHERE task_draft_id = $1", draftID)
|
||||
}
|
||||
log.Printf("Fitbit: set task draft auto_complete for task_id=%d to %v", taskID, autoComplete)
|
||||
return nil
|
||||
}
|
||||
|
||||
// fitbitSyncHandler выполняет ручную синхронизацию данных Fitbit
|
||||
func (a *App) fitbitSyncHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "OPTIONS" {
|
||||
|
||||
Reference in New Issue
Block a user