category.go 1.1 KB

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