entry.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2021 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 validator // import "miniflux.app/validator"
  5. import (
  6. "fmt"
  7. "miniflux.app/model"
  8. )
  9. // ValidateEntriesStatusUpdateRequest validates a status update for a list of entries.
  10. func ValidateEntriesStatusUpdateRequest(request *model.EntriesStatusUpdateRequest) error {
  11. if len(request.EntryIDs) == 0 {
  12. return fmt.Errorf(`The list of entries cannot be empty`)
  13. }
  14. return ValidateEntryStatus(request.Status)
  15. }
  16. // ValidateEntryStatus makes sure the entry status is valid.
  17. func ValidateEntryStatus(status string) error {
  18. switch status {
  19. case model.EntryStatusRead, model.EntryStatusUnread, model.EntryStatusRemoved:
  20. return nil
  21. }
  22. return fmt.Errorf(`Invalid entry status, valid status values are: "%s", "%s" and "%s"`, model.EntryStatusRead, model.EntryStatusUnread, model.EntryStatusRemoved)
  23. }
  24. // ValidateEntryOrder makes sure the sorting order is valid.
  25. func ValidateEntryOrder(order string) error {
  26. switch order {
  27. case "id", "status", "changed_at", "published_at", "created_at", "category_title", "category_id", "title", "author":
  28. return nil
  29. }
  30. return fmt.Errorf(`Invalid entry order, valid order values are: "id", "status", "changed_at", "published_at", "created_at", "category_title", "category_id", "title", "author"`)
  31. }