Add API endpoint to flush history

This commit is contained in:
Frédéric Guillot 2023-10-05 21:37:45 -07:00
parent 1350f84ea4
commit 5774323f2e
5 changed files with 48 additions and 4 deletions

View file

@ -512,6 +512,12 @@ func (c *Client) FetchCounters() (*FeedCounters, error) {
return &result, nil
}
// FlushHistory changes all entries with the status "read" to "removed".
func (c *Client) FlushHistory() error {
_, err := c.request.Put("/v1/flush-history", nil)
return err
}
func buildFilterQueryString(path string, filter *Filter) string {
if filter != nil {
values := url.Values{}

View file

@ -66,4 +66,5 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
sr.HandleFunc("/entries/{entryID}/bookmark", handler.toggleBookmark).Methods(http.MethodPut)
sr.HandleFunc("/entries/{entryID}/save", handler.saveEntry).Methods(http.MethodPost)
sr.HandleFunc("/entries/{entryID}/fetch-content", handler.fetchContent).Methods(http.MethodGet)
sr.HandleFunc("/flush-history", handler.flushHistory).Methods(http.MethodPut, http.MethodDelete)
}

View file

@ -283,6 +283,12 @@ func (h *handler) fetchContent(w http.ResponseWriter, r *http.Request) {
json.OK(w, r, map[string]string{"content": entry.Content})
}
func (h *handler) flushHistory(w http.ResponseWriter, r *http.Request) {
loggedUserID := request.UserID(r)
go h.store.FlushHistory(loggedUserID)
json.Accepted(w, r)
}
func configureFilters(builder *storage.EntryQueryBuilder, r *http.Request) {
if beforeEntryID := request.QueryInt64Param(r, "before_entry_id", 0); beforeEntryID > 0 {
builder.BeforeEntryID(beforeEntryID)

View file

@ -442,7 +442,7 @@ func (s *Storage) ToggleBookmark(userID int64, entryID int64) error {
return nil
}
// FlushHistory set all entries with the status "read" to "removed".
// FlushHistory changes all entries with the status "read" to "removed".
func (s *Storage) FlushHistory(userID int64) error {
query := `
UPDATE

View file

@ -434,9 +434,9 @@ func TestHistoryOrder(t *testing.T) {
t.Fatal(err)
}
selectedEntry := result.Entries[2].ID
selectedEntryID := result.Entries[2].ID
err = client.UpdateEntries([]int64{selectedEntry}, miniflux.EntryStatusRead)
err = client.UpdateEntries([]int64{selectedEntryID}, miniflux.EntryStatusRead)
if err != nil {
t.Fatal(err)
}
@ -446,7 +446,38 @@ func TestHistoryOrder(t *testing.T) {
t.Fatal(err)
}
if history.Entries[0].ID != selectedEntry {
if history.Entries[0].ID != selectedEntryID {
t.Fatal("The entry that we just read should be at the top of the history")
}
}
func TestFlushHistory(t *testing.T) {
client := createClient(t)
createFeed(t, client)
result, err := client.Entries(&miniflux.Filter{Limit: 1})
if err != nil {
t.Fatal(err)
}
selectedEntryID := result.Entries[0].ID
err = client.UpdateEntries([]int64{selectedEntryID}, miniflux.EntryStatusRead)
if err != nil {
t.Fatal(err)
}
err = client.FlushHistory()
if err != nil {
t.Fatal(err)
}
history, err := client.Entries(&miniflux.Filter{Status: miniflux.EntryStatusRemoved})
if err != nil {
t.Fatal(err)
}
if history.Entries[0].ID != selectedEntryID {
t.Fatal("The entry that we just read should have the removed status")
}
}