2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2021-01-05 00:32:32 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package validator // import "miniflux.app/v2/internal/validator"
|
2021-01-05 00:32:32 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/model"
|
2021-01-05 00:32:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ValidateEntriesStatusUpdateRequest validates a status update for a list of entries.
|
|
|
|
func ValidateEntriesStatusUpdateRequest(request *model.EntriesStatusUpdateRequest) error {
|
|
|
|
if len(request.EntryIDs) == 0 {
|
2023-10-07 07:42:59 +02:00
|
|
|
return fmt.Errorf(`the list of entries cannot be empty`)
|
2021-01-05 00:32:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ValidateEntryStatus(request.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateEntryStatus makes sure the entry status is valid.
|
|
|
|
func ValidateEntryStatus(status string) error {
|
|
|
|
switch status {
|
|
|
|
case model.EntryStatusRead, model.EntryStatusUnread, model.EntryStatusRemoved:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-07 07:42:59 +02:00
|
|
|
return fmt.Errorf(`invalid entry status, valid status values are: "%s", "%s" and "%s"`, model.EntryStatusRead, model.EntryStatusUnread, model.EntryStatusRemoved)
|
2021-01-05 00:32:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateEntryOrder makes sure the sorting order is valid.
|
|
|
|
func ValidateEntryOrder(order string) error {
|
|
|
|
switch order {
|
2022-07-19 01:16:36 +02:00
|
|
|
case "id", "status", "changed_at", "published_at", "created_at", "category_title", "category_id", "title", "author":
|
2021-01-05 00:32:32 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-07 07:42:59 +02:00
|
|
|
return fmt.Errorf(`invalid entry order, valid order values are: "id", "status", "changed_at", "published_at", "created_at", "category_title", "category_id", "title", "author"`)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateEntryModification makes sure the entry modification is valid.
|
|
|
|
func ValidateEntryModification(request *model.EntryUpdateRequest) error {
|
|
|
|
if request.Title != nil && *request.Title == "" {
|
|
|
|
return fmt.Errorf(`the entry title cannot be empty`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if request.Content != nil && *request.Content == "" {
|
|
|
|
return fmt.Errorf(`the entry content cannot be empty`)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2021-01-05 00:32:32 +01:00
|
|
|
}
|