category.go 704 B

12345678910111213141516171819202122232425262728293031323334
  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
  5. import (
  6. "errors"
  7. "github.com/miniflux/miniflux2/model"
  8. "net/http"
  9. )
  10. // CategoryForm represents a feed form in the UI
  11. type CategoryForm struct {
  12. Title string
  13. }
  14. func (c CategoryForm) Validate() error {
  15. if c.Title == "" {
  16. return errors.New("The title is mandatory.")
  17. }
  18. return nil
  19. }
  20. func (c CategoryForm) Merge(category *model.Category) *model.Category {
  21. category.Title = c.Title
  22. return category
  23. }
  24. func NewCategoryForm(r *http.Request) *CategoryForm {
  25. return &CategoryForm{
  26. Title: r.FormValue("title"),
  27. }
  28. }