Cleanup/Comments/Reorganization

This commit is contained in:
kolaente 2020-04-18 22:59:54 +02:00
parent e938be1936
commit eaa252b6ee
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 11 additions and 12 deletions

View File

@ -56,14 +56,6 @@ func getBucketByID(id int64) (b *Bucket, err error) {
return
}
// Create creates a new bucket
func (b *Bucket) Create(a web.Auth) (err error) {
b.CreatedByID = a.GetID()
_, err = x.Insert(b)
return
}
// ReadAll returns all buckets with their tasks for a certain list
func (b *Bucket) ReadAll(auth web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) {
@ -101,17 +93,24 @@ func (b *Bucket) ReadAll(auth web.Auth, search string, page int, perPage int) (r
return
}
// Put all tasks in their buckets
// All tasks which are not associated to any bucket will have bucket id 0 which is the nil value for int64
// Since we created a bucked with that id at the beginning, all tasks should be in there.
for _, task := range tasks {
bucketMap[task.BucketID].Tasks = append(bucketMap[task.BucketID].Tasks, task)
}
// Put all tasks in their buckets
// Put all tasks which are not explicitly associated to a bucket into a pseudo bucket
return buckets, len(buckets), int64(len(buckets)), nil
}
// Create creates a new bucket
func (b *Bucket) Create(a web.Auth) (err error) {
b.CreatedByID = a.GetID()
_, err = x.Insert(b)
return
}
// Update Updates an existing bucket
func (b *Bucket) Update() (err error) {
_, err = x.Where("id = ?", b.ID).Update(b)