Add list background information when getting all lists
This commit is contained in:
parent
24c1098736
commit
ca4d5000ed
2 changed files with 26 additions and 9 deletions
|
@ -329,21 +329,37 @@ func AddListDetails(lists []*List) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all list owners
|
// Get all list owners
|
||||||
owners := []*user.User{}
|
owners := map[int64]*user.User{}
|
||||||
err = x.In("id", ownerIDs).Find(&owners)
|
err = x.In("id", ownerIDs).Find(&owners)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fileIDs []int64
|
||||||
|
for _, l := range lists {
|
||||||
|
if o, exists := owners[l.OwnerID]; exists {
|
||||||
|
l.Owner = o
|
||||||
|
}
|
||||||
|
if l.BackgroundFileID != 0 {
|
||||||
|
l.BackgroundInformation = &ListBackgroundType{Type: ListBackgroundUpload}
|
||||||
|
}
|
||||||
|
fileIDs = append(fileIDs, l.BackgroundFileID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unsplash background file info
|
||||||
|
us := []*UnsplashPhoto{}
|
||||||
|
err = x.In("file_id", fileIDs).Find(&us)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
unsplashPhotos := make(map[int64]*UnsplashPhoto, len(us))
|
||||||
|
for _, u := range us {
|
||||||
|
unsplashPhotos[u.FileID] = u
|
||||||
|
}
|
||||||
|
|
||||||
// Build it all into the lists slice
|
// Build it all into the lists slice
|
||||||
for in, list := range lists {
|
for _, l := range lists {
|
||||||
// Owner
|
l.BackgroundInformation = unsplashPhotos[l.BackgroundFileID]
|
||||||
for _, owner := range owners {
|
|
||||||
if list.OwnerID == owner.ID {
|
|
||||||
lists[in].Owner = owner
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -52,6 +52,7 @@ func GetTables() []interface{} {
|
||||||
&TaskAttachment{},
|
&TaskAttachment{},
|
||||||
&TaskComment{},
|
&TaskComment{},
|
||||||
&Bucket{},
|
&Bucket{},
|
||||||
|
&UnsplashPhoto{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue