Add moving new tasks into the default bucket when none was provided
Some checks reported errors
continuous-integration/drone/pr Build was killed
Some checks reported errors
continuous-integration/drone/pr Build was killed
This commit is contained in:
parent
cb14ff81d4
commit
4e33e5bc93
|
@ -63,6 +63,15 @@ func getBucketByID(id int64) (b *Bucket, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func getDefaultBucket(listID int64) (bucket *Bucket, err error) {
|
||||
bucket = &Bucket{}
|
||||
_, err = x.
|
||||
Where("list_id = ?", listID).
|
||||
OrderBy("id asc").
|
||||
Get(bucket)
|
||||
return
|
||||
}
|
||||
|
||||
// ReadAll returns all buckets with their tasks for a certain list
|
||||
// @Summary Get all kanban buckets of a list
|
||||
// @Description Returns all kanban buckets with belong to a list including their tasks.
|
||||
|
@ -197,11 +206,7 @@ func (b *Bucket) Delete() (err error) {
|
|||
}
|
||||
|
||||
// Get the default bucket
|
||||
defaultBucket := &Bucket{}
|
||||
_, err = x.
|
||||
Where("list_id = ?", b.ListID).
|
||||
OrderBy("id asc").
|
||||
Get(defaultBucket)
|
||||
defaultBucket, err := getDefaultBucket(b.ListID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -544,6 +544,15 @@ func (t *Task) Create(a web.Auth) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Get the default bucket and move the task there
|
||||
if t.BucketID == 0 {
|
||||
defaultBucket, err := getDefaultBucket(t.ListID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.BucketID = defaultBucket.ID
|
||||
}
|
||||
|
||||
// Get the index for this task
|
||||
latestTask := &Task{}
|
||||
_, err = x.Where("list_id = ?", t.ListID).OrderBy("id desc").Get(latestTask)
|
||||
|
|
|
@ -47,6 +47,8 @@ func TestTask_Create(t *testing.T) {
|
|||
// Assert getting a new index
|
||||
assert.NotEmpty(t, task.Index)
|
||||
assert.Equal(t, int64(18), task.Index)
|
||||
// Assert moving it into the default bucket
|
||||
assert.Equal(t, int64(1), task.BucketID)
|
||||
|
||||
})
|
||||
t.Run("empty text", func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user