category.go 885 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2017 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 form // import "miniflux.app/ui/form"
  5. import (
  6. "net/http"
  7. "miniflux.app/errors"
  8. "miniflux.app/model"
  9. )
  10. // CategoryForm represents a feed form in the UI
  11. type CategoryForm struct {
  12. Title string
  13. }
  14. // Validate makes sure the form values are valid.
  15. func (c CategoryForm) Validate() error {
  16. if c.Title == "" {
  17. return errors.NewLocalizedError("error.title_required")
  18. }
  19. return nil
  20. }
  21. // Merge update the given category fields.
  22. func (c CategoryForm) Merge(category *model.Category) *model.Category {
  23. category.Title = c.Title
  24. return category
  25. }
  26. // NewCategoryForm returns a new CategoryForm.
  27. func NewCategoryForm(r *http.Request) *CategoryForm {
  28. return &CategoryForm{
  29. Title: r.FormValue("title"),
  30. }
  31. }