Allow API search for entries which are not starred
This commit is contained in:
parent
fa8431c5c6
commit
fb585d0086
8 changed files with 24 additions and 10 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
json_parser "encoding/json"
|
json_parser "encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"miniflux.app/http/request"
|
"miniflux.app/http/request"
|
||||||
|
@ -240,7 +241,10 @@ func configureFilters(builder *storage.EntryQueryBuilder, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.HasQueryParam(r, "starred") {
|
if request.HasQueryParam(r, "starred") {
|
||||||
builder.WithStarred()
|
starred, err := strconv.ParseBool(r.URL.Query().Get("starred"))
|
||||||
|
if err == nil {
|
||||||
|
builder.WithStarred(starred)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
searchQuery := request.QueryStringParam(r, "search", "")
|
searchQuery := request.QueryStringParam(r, "search", "")
|
||||||
|
|
|
@ -542,8 +542,8 @@ func buildFilterQueryString(path string, filter *Filter) string {
|
||||||
values.Set("before_entry_id", strconv.FormatInt(filter.BeforeEntryID, 10))
|
values.Set("before_entry_id", strconv.FormatInt(filter.BeforeEntryID, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
if filter.Starred {
|
if filter.Starred != "" {
|
||||||
values.Set("starred", "1")
|
values.Set("starred", filter.Starred)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filter.Search != "" {
|
if filter.Search != "" {
|
||||||
|
|
|
@ -221,6 +221,11 @@ type Enclosure struct {
|
||||||
// Enclosures represents a list of attachments.
|
// Enclosures represents a list of attachments.
|
||||||
type Enclosures []*Enclosure
|
type Enclosures []*Enclosure
|
||||||
|
|
||||||
|
const (
|
||||||
|
FilterNotStarred = "0"
|
||||||
|
FilterOnlyStarred = "1"
|
||||||
|
)
|
||||||
|
|
||||||
// Filter is used to filter entries.
|
// Filter is used to filter entries.
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
Status string
|
Status string
|
||||||
|
@ -228,7 +233,7 @@ type Filter struct {
|
||||||
Limit int
|
Limit int
|
||||||
Order string
|
Order string
|
||||||
Direction string
|
Direction string
|
||||||
Starred bool
|
Starred string
|
||||||
Before int64
|
Before int64
|
||||||
After int64
|
After int64
|
||||||
BeforeEntryID int64
|
BeforeEntryID int64
|
||||||
|
|
|
@ -365,7 +365,7 @@ func (h *handler) handleSavedItems(w http.ResponseWriter, r *http.Request) {
|
||||||
logger.Debug("[Fever] Fetching saved items for user #%d", userID)
|
logger.Debug("[Fever] Fetching saved items for user #%d", userID)
|
||||||
|
|
||||||
builder := h.store.NewEntryQueryBuilder(userID)
|
builder := h.store.NewEntryQueryBuilder(userID)
|
||||||
builder.WithStarred()
|
builder.WithStarred(true)
|
||||||
|
|
||||||
entryIDs, err := builder.GetEntryIDs()
|
entryIDs, err := builder.GetEntryIDs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1141,7 +1141,7 @@ func (h *handler) handleStarredStream(w http.ResponseWriter, r *http.Request, rm
|
||||||
clientIP := request.ClientIP(r)
|
clientIP := request.ClientIP(r)
|
||||||
|
|
||||||
builder := h.store.NewEntryQueryBuilder(rm.UserID)
|
builder := h.store.NewEntryQueryBuilder(rm.UserID)
|
||||||
builder.WithStarred()
|
builder.WithStarred(true)
|
||||||
builder.WithLimit(rm.Count)
|
builder.WithLimit(rm.Count)
|
||||||
builder.WithOrder(model.DefaultSortingOrder)
|
builder.WithOrder(model.DefaultSortingOrder)
|
||||||
builder.WithDirection(rm.SortDirection)
|
builder.WithDirection(rm.SortDirection)
|
||||||
|
|
|
@ -42,8 +42,12 @@ func (e *EntryQueryBuilder) WithSearchQuery(query string) *EntryQueryBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithStarred adds starred filter.
|
// WithStarred adds starred filter.
|
||||||
func (e *EntryQueryBuilder) WithStarred() *EntryQueryBuilder {
|
func (e *EntryQueryBuilder) WithStarred(starred bool) *EntryQueryBuilder {
|
||||||
e.conditions = append(e.conditions, "e.starred is true")
|
if starred {
|
||||||
|
e.conditions = append(e.conditions, "e.starred is true")
|
||||||
|
} else {
|
||||||
|
e.conditions = append(e.conditions, "e.starred is false")
|
||||||
|
}
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Use of this source code is governed by the Apache 2.0
|
// Use of this source code is governed by the Apache 2.0
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build integration
|
||||||
// +build integration
|
// +build integration
|
||||||
|
|
||||||
package tests
|
package tests
|
||||||
|
@ -123,7 +124,7 @@ func TestGetAllEntries(t *testing.T) {
|
||||||
t.Fatalf(`The items should be sorted differently "%v" vs "%v"`, resultWithDifferentSorting.Entries[0].Title, resultWithoutSorting.Entries[0].Title)
|
t.Fatalf(`The items should be sorted differently "%v" vs "%v"`, resultWithDifferentSorting.Entries[0].Title, resultWithoutSorting.Entries[0].Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
resultWithStarredEntries, err := client.Entries(&miniflux.Filter{Starred: true})
|
resultWithStarredEntries, err := client.Entries(&miniflux.Filter{Starred: miniflux.FilterOnlyStarred})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (h *handler) showStarredPage(w http.ResponseWriter, r *http.Request) {
|
||||||
offset := request.QueryIntParam(r, "offset", 0)
|
offset := request.QueryIntParam(r, "offset", 0)
|
||||||
builder := h.store.NewEntryQueryBuilder(user.ID)
|
builder := h.store.NewEntryQueryBuilder(user.ID)
|
||||||
builder.WithoutStatus(model.EntryStatusRemoved)
|
builder.WithoutStatus(model.EntryStatusRemoved)
|
||||||
builder.WithStarred()
|
builder.WithStarred(true)
|
||||||
builder.WithOrder(user.EntryOrder)
|
builder.WithOrder(user.EntryOrder)
|
||||||
builder.WithDirection(user.EntryDirection)
|
builder.WithDirection(user.EntryDirection)
|
||||||
builder.WithOffset(offset)
|
builder.WithOffset(offset)
|
||||||
|
|
Loading…
Add table
Reference in a new issue