category.go 1.0 KB

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