entry_update_status.go 958 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 // import "miniflux.app/ui"
  5. import (
  6. "errors"
  7. "net/http"
  8. "miniflux.app/http/request"
  9. "miniflux.app/http/response/json"
  10. "miniflux.app/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. err = c.store.SetEntriesStatus(request.UserID(r), entryIDs, status)
  25. if err != nil {
  26. logger.Error("[Controller:UpdateEntryStatus] %v", err)
  27. json.ServerError(w, nil)
  28. return
  29. }
  30. json.OK(w, r, "OK")
  31. }