entry.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package validator // import "miniflux.app/v2/internal/validator"
  4. import (
  5. "fmt"
  6. "miniflux.app/v2/internal/model"
  7. )
  8. // ValidateEntriesStatusUpdateRequest validates a status update for a list of entries.
  9. func ValidateEntriesStatusUpdateRequest(request *model.EntriesStatusUpdateRequest) error {
  10. if len(request.EntryIDs) == 0 {
  11. return fmt.Errorf(`The list of entries cannot be empty`)
  12. }
  13. return ValidateEntryStatus(request.Status)
  14. }
  15. // ValidateEntryStatus makes sure the entry status is valid.
  16. func ValidateEntryStatus(status string) error {
  17. switch status {
  18. case model.EntryStatusRead, model.EntryStatusUnread, model.EntryStatusRemoved:
  19. return nil
  20. }
  21. return fmt.Errorf(`Invalid entry status, valid status values are: "%s", "%s" and "%s"`, model.EntryStatusRead, model.EntryStatusUnread, model.EntryStatusRemoved)
  22. }
  23. // ValidateEntryOrder makes sure the sorting order is valid.
  24. func ValidateEntryOrder(order string) error {
  25. switch order {
  26. case "id", "status", "changed_at", "published_at", "created_at", "category_title", "category_id", "title", "author":
  27. return nil
  28. }
  29. return fmt.Errorf(`Invalid entry order, valid order values are: "id", "status", "changed_at", "published_at", "created_at", "category_title", "category_id", "title", "author"`)
  30. }