Add query to get all Lists (to be used by List index page)
This commit is contained in:
parent
8d61aec316
commit
ea1d04f2f0
@ -95,7 +95,14 @@ func (p Profile) GetListUsers(list_id ListID) []User {
|
||||
return ret
|
||||
}
|
||||
|
||||
// XXX
|
||||
// func (p Profile) GetFollowedUsers() List {
|
||||
// err =
|
||||
// }
|
||||
func (p Profile) GetAllLists() []List {
|
||||
var lists []List
|
||||
err := p.DB.Select(&lists, `select rowid, is_online, online_list_id, name from lists`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := range lists {
|
||||
lists[i].Users = p.GetListUsers(lists[i].ID)
|
||||
}
|
||||
return lists
|
||||
}
|
||||
|
@ -152,3 +152,20 @@ func TestAddAndRemoveUserToList(t *testing.T) {
|
||||
// Should be gone
|
||||
require.Len(profile.GetListUsers(l.ID), 0)
|
||||
}
|
||||
|
||||
func TestGetAllLists(t *testing.T) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
profile, err := persistence.LoadProfile("../../sample_data/profile")
|
||||
require.NoError(err)
|
||||
|
||||
// Create a list
|
||||
l := List{IsOnline: false, Name: fmt.Sprintf("Test List %d", rand.Int())}
|
||||
profile.SaveList(&l)
|
||||
|
||||
// Get all the lists
|
||||
lists := profile.GetAllLists()
|
||||
assert.True(len(lists) > 1) // Should be at least Offline Follows and `l`
|
||||
assert.Contains(lists, l)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user