category.go 1.1 KB

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