Add pagination for buckets by default

This commit is contained in:
kolaente 2021-02-28 17:18:30 +01:00
parent 3999580fe6
commit ff0f0f6989
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 28 additions and 11 deletions

View File

@ -99,9 +99,6 @@ func getDefaultBucket(s *xorm.Session, listID int64) (bucket *Bucket, err error)
// @Router /lists/{id}/buckets [get]
func (b *Bucket) ReadAll(s *xorm.Session, auth web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) {
// Note: I'm ignoring pagination for now since I've yet to figure out a way on how to make it work
// I'll probably just don't do it and instead make individual tasks archivable.
// Get all buckets for this list
buckets := []*Bucket{}
err = s.Where("list_id = ?", b.ListID).Find(&buckets)
@ -128,16 +125,36 @@ func (b *Bucket) ReadAll(s *xorm.Session, auth web.Auth, search string, page int
bb.CreatedBy = users[bb.CreatedByID]
}
// Get all tasks for this list
b.TaskCollection.ListID = b.ListID
b.TaskCollection.OrderBy = []string{string(orderAscending)}
b.TaskCollection.SortBy = []string{taskPropertyPosition}
ts, _, _, err := b.TaskCollection.ReadAll(s, auth, "", -1, 0)
if err != nil {
return
tasks := []*Task{}
for id, bucket := range bucketMap {
ts, _, _, err := getRawTasksForLists(s, []*List{{ID: bucket.ListID}}, auth, &taskOptions{
page: 1,
perPage: perPage,
filters: []*taskFilter{
{
field: "bucket_id",
value: id,
comparator: taskFilterComparatorEquals,
},
},
})
if err != nil {
return nil, 0, 0, err
}
tasks = append(tasks, ts...)
}
tasks := ts.([]*Task)
taskMap := make(map[int64]*Task, len(tasks))
for _, t := range tasks {
taskMap[t.ID] = t
}
err = addMoreInfoToTasks(s, taskMap)
if err != nil {
return nil, 0, 0, err
}
// 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