Изменить логику выставления next_show_at: для repetition_period - сегодняшняя дата, для repetition_date - следующая подходящая дата
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 57s

This commit is contained in:
poignatov
2026-01-09 13:35:46 +03:00
parent 60a6f4deb4
commit b57b0bc901
2 changed files with 17 additions and 45 deletions

View File

@@ -1 +1 @@
3.5.0 3.5.1

View File

@@ -6876,28 +6876,14 @@ func (a *App) createTaskHandler(w http.ResponseWriter, r *http.Request) {
var insertSQL string var insertSQL string
var insertArgs []interface{} var insertArgs []interface{}
if repetitionPeriod.Valid { if repetitionPeriod.Valid {
// Вычисляем next_show_at для задачи с repetition_period // Для repetition_period выставляем сегодняшнюю дату
periodStr := strings.TrimSpace(repetitionPeriod.String) now := time.Now()
isZeroPeriod := strings.HasPrefix(periodStr, "0 ") || periodStr == "0" insertSQL = `
var nextShowAt *time.Time INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, next_show_at, completed, deleted)
if !isZeroPeriod { VALUES ($1, $2, $3, $4, $5::INTERVAL, NULL, $6, 0, FALSE)
nextShowAt = calculateNextShowAtFromRepetitionPeriod(repetitionPeriod.String, time.Now()) RETURNING id
} `
if nextShowAt != nil { insertArgs = []interface{}{userID, strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriodValue, now}
insertSQL = `
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, next_show_at, completed, deleted)
VALUES ($1, $2, $3, $4, $5::INTERVAL, NULL, $6, 0, FALSE)
RETURNING id
`
insertArgs = []interface{}{userID, strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriodValue, nextShowAt}
} else {
insertSQL = `
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, completed, deleted)
VALUES ($1, $2, $3, $4, $5::INTERVAL, NULL, 0, FALSE)
RETURNING id
`
insertArgs = []interface{}{userID, strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriodValue}
}
} else if repetitionDate.Valid { } else if repetitionDate.Valid {
// Вычисляем next_show_at для задачи с repetition_date // Вычисляем next_show_at для задачи с repetition_date
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now()) nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
@@ -7149,28 +7135,14 @@ func (a *App) updateTaskHandler(w http.ResponseWriter, r *http.Request) {
var updateSQL string var updateSQL string
var updateArgs []interface{} var updateArgs []interface{}
if repetitionPeriod.Valid { if repetitionPeriod.Valid {
// Вычисляем next_show_at для задачи с repetition_period // Для repetition_period выставляем сегодняшнюю дату
periodStr := strings.TrimSpace(repetitionPeriod.String) now := time.Now()
isZeroPeriod := strings.HasPrefix(periodStr, "0 ") || periodStr == "0" updateSQL = `
var nextShowAt *time.Time UPDATE tasks
if !isZeroPeriod { SET name = $1, reward_message = $2, progression_base = $3, repetition_period = $4::INTERVAL, repetition_date = NULL, next_show_at = $5
nextShowAt = calculateNextShowAtFromRepetitionPeriod(repetitionPeriod.String, time.Now()) WHERE id = $6
} `
if nextShowAt != nil { updateArgs = []interface{}{strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriod.String, now, taskID}
updateSQL = `
UPDATE tasks
SET name = $1, reward_message = $2, progression_base = $3, repetition_period = $4::INTERVAL, repetition_date = NULL, next_show_at = $5
WHERE id = $6
`
updateArgs = []interface{}{strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriod.String, nextShowAt, taskID}
} else {
updateSQL = `
UPDATE tasks
SET name = $1, reward_message = $2, progression_base = $3, repetition_period = $4::INTERVAL, repetition_date = NULL, next_show_at = NULL
WHERE id = $5
`
updateArgs = []interface{}{strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriod.String, taskID}
}
} else if repetitionDate.Valid { } else if repetitionDate.Valid {
// Вычисляем next_show_at для задачи с repetition_date // Вычисляем next_show_at для задачи с repetition_date
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now()) nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())