category.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 model // import "miniflux.app/model"
  5. import (
  6. "errors"
  7. "fmt"
  8. )
  9. // Category represents a category in the system.
  10. type Category struct {
  11. ID int64 `json:"id,omitempty"`
  12. Title string `json:"title,omitempty"`
  13. UserID int64 `json:"user_id,omitempty"`
  14. FeedCount int `json:"nb_feeds,omitempty"`
  15. }
  16. func (c *Category) String() string {
  17. return fmt.Sprintf("ID=%d, UserID=%d, Title=%s", c.ID, c.UserID, c.Title)
  18. }
  19. // ValidateCategoryCreation validates a category during the creation.
  20. func (c Category) ValidateCategoryCreation() error {
  21. if c.Title == "" {
  22. return errors.New("The title is mandatory")
  23. }
  24. if c.UserID == 0 {
  25. return errors.New("The userID is mandatory")
  26. }
  27. return nil
  28. }
  29. // ValidateCategoryModification validates a category during the modification.
  30. func (c Category) ValidateCategoryModification() error {
  31. if c.Title == "" {
  32. return errors.New("The title is mandatory")
  33. }
  34. if c.UserID == 0 {
  35. return errors.New("The userID is mandatory")
  36. }
  37. if c.ID <= 0 {
  38. return errors.New("The ID is mandatory")
  39. }
  40. return nil
  41. }
  42. // Categories represents a list of categories.
  43. type Categories []*Category