When updating a list task, all relevant values are now updated.
This commit is contained in:
parent
5b8cd30736
commit
431564d63c
3 changed files with 23 additions and 9 deletions
9
Gopkg.lock
generated
9
Gopkg.lock
generated
|
@ -72,6 +72,14 @@
|
|||
revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:8eb1de8112c9924d59bf1d3e5c26f5eaa2bfc2a5fcbb92dc1c2e4546d695f277"
|
||||
name = "github.com/imdario/mergo"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "9f23e2d6bd2a77f959b2bf6acdbefd708a83a4a4"
|
||||
version = "v0.3.6"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:82c5850e702ccef3976cdfdf737725013587c64e02e5ecae57e86431163b27aa"
|
||||
name = "github.com/labstack/echo"
|
||||
|
@ -274,6 +282,7 @@
|
|||
"github.com/go-sql-driver/mysql",
|
||||
"github.com/go-xorm/core",
|
||||
"github.com/go-xorm/xorm",
|
||||
"github.com/imdario/mergo",
|
||||
"github.com/labstack/echo",
|
||||
"github.com/labstack/echo/middleware",
|
||||
"github.com/mattn/go-sqlite3",
|
||||
|
|
|
@ -47,3 +47,7 @@
|
|||
[[constraint]]
|
||||
name = "github.com/spf13/viper"
|
||||
version = "1.2.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/imdario/mergo"
|
||||
version = "0.3.6"
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
// Create is the implementation to create a list task
|
||||
func (i *ListTask) Create(doer *User) (err error) {
|
||||
i.ID = 0
|
||||
|
@ -34,17 +38,14 @@ func (i *ListTask) Update() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// If we dont have a text, use the one from the original task
|
||||
if i.Text == "" {
|
||||
i.Text = ot.Text
|
||||
}
|
||||
|
||||
// For whatever reason, xorm dont detect if done is updated, so we need to update this every time by hand
|
||||
if i.Done != ot.Done {
|
||||
_, err = x.ID(i.ID).Cols("done").Update(i)
|
||||
return
|
||||
// Which is why we merge the actual task struct with the one we got from the user.
|
||||
// The user struct ovverrides values in the actual one.
|
||||
if err := mergo.Merge(&ot, i, mergo.WithOverride); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = x.ID(i.ID).Update(i)
|
||||
_, err = x.ID(i.ID).Cols("text", "description", "done", "due_date_unix", "reminder_unix").Update(ot)
|
||||
*i = ot
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue