category.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. "miniflux.app/v2/internal/locale"
  6. "miniflux.app/v2/internal/model"
  7. "miniflux.app/v2/internal/storage"
  8. )
  9. // ValidateCategoryCreation validates category creation.
  10. func ValidateCategoryCreation(store *storage.Storage, userID int64, request *model.CategoryRequest) *locale.LocalizedError {
  11. if request.Title == "" {
  12. return locale.NewLocalizedError("error.title_required")
  13. }
  14. if store.CategoryTitleExists(userID, request.Title) {
  15. return locale.NewLocalizedError("error.category_already_exists")
  16. }
  17. return nil
  18. }
  19. // ValidateCategoryModification validates category modification.
  20. func ValidateCategoryModification(store *storage.Storage, userID, categoryID int64, request *model.CategoryRequest) *locale.LocalizedError {
  21. if request.Title == "" {
  22. return locale.NewLocalizedError("error.title_required")
  23. }
  24. if store.AnotherCategoryExists(userID, categoryID, request.Title) {
  25. return locale.NewLocalizedError("error.category_already_exists")
  26. }
  27. return nil
  28. }