entry_update_status.go 996 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui
  5. import (
  6. "errors"
  7. "net/http"
  8. "github.com/miniflux/miniflux/http/context"
  9. "github.com/miniflux/miniflux/http/response/json"
  10. "github.com/miniflux/miniflux/logger"
  11. )
  12. // UpdateEntriesStatus updates the status for a list of entries.
  13. func (c *Controller) UpdateEntriesStatus(w http.ResponseWriter, r *http.Request) {
  14. entryIDs, status, err := decodeEntryStatusPayload(r.Body)
  15. if err != nil {
  16. logger.Error("[Controller:UpdateEntryStatus] %v", err)
  17. json.BadRequest(w, nil)
  18. return
  19. }
  20. if len(entryIDs) == 0 {
  21. json.BadRequest(w, errors.New("The list of entryID is empty"))
  22. return
  23. }
  24. ctx := context.New(r)
  25. err = c.store.SetEntriesStatus(ctx.UserID(), entryIDs, status)
  26. if err != nil {
  27. logger.Error("[Controller:UpdateEntryStatus] %v", err)
  28. json.ServerError(w, nil)
  29. return
  30. }
  31. json.OK(w, r, "OK")
  32. }