Add moving new tasks into the default bucket when none was provided
continuous-integration/drone/pr Build was killed Details

This commit is contained in:
kolaente 2020-04-25 22:01:49 +02:00
parent cb14ff81d4
commit 4e33e5bc93
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 21 additions and 5 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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) {