Add basic sorting to management interface

This commit is contained in:
2022-06-07 16:25:45 +09:30
parent 42fd1973b8
commit 6cf327226d
4 changed files with 21 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ type BookmarkManager struct {
type SearchOptions struct {
Query string
Tags []string
Sort string
}
func NewBookmarkManager(db *DB) *BookmarkManager {
@@ -138,10 +139,22 @@ func (m *BookmarkManager) Search(opts SearchOptions) ([]entity.Bookmark, error)
bhQuery = bolthold.Query(*bhQuery.And("Tags").ContainsAll(bolthold.Slice(opts.Tags)...))
}
if opts.Sort == "title" {
bhQuery.SortBy("Info.Title")
} else if opts.Sort == "created" {
bhQuery.SortBy("TimestampCreated")
} else if opts.Sort == "scraped" {
bhQuery.SortBy("TimestampLastScraped")
} else {
bhQuery.SortBy("ID")
}
out := []entity.Bookmark{}
err := m.db.store.ForEach(&bhQuery,
func(bm *entity.Bookmark) error {
out = append(out, *bm)
return nil
})
if err != nil {