aboutsummaryrefslogtreecommitdiffhomepage
path: root/model/category.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2017-11-25 19:06:02 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2017-11-25 19:06:02 -0800
commit51f77754660ddcd29f61be293a8e405d8cd3ba18 (patch)
treec421b1ab2a470e23e3ce6dbf2d09878087ebd614 /model/category.go
parent4560af165e7fa25dddd46f49ad4a0d9f3149336c (diff)
Add unit tests for models
Diffstat (limited to 'model/category.go')
-rw-r--r--model/category.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/model/category.go b/model/category.go
index 76f254f..1c72851 100644
--- a/model/category.go
+++ b/model/category.go
@@ -9,6 +9,7 @@ import (
"fmt"
)
+// Category represents a category in the system.
type Category struct {
ID int64 `json:"id,omitempty"`
Title string `json:"title,omitempty"`
@@ -20,6 +21,7 @@ func (c *Category) String() string {
return fmt.Sprintf("ID=%d, UserID=%d, Title=%s", c.ID, c.UserID, c.Title)
}
+// ValidateCategoryCreation validates a category during the creation.
func (c Category) ValidateCategoryCreation() error {
if c.Title == "" {
return errors.New("The title is mandatory")
@@ -32,6 +34,7 @@ func (c Category) ValidateCategoryCreation() error {
return nil
}
+// ValidateCategoryModification validates a category during the modification.
func (c Category) ValidateCategoryModification() error {
if c.Title == "" {
return errors.New("The title is mandatory")
@@ -41,11 +44,12 @@ func (c Category) ValidateCategoryModification() error {
return errors.New("The userID is mandatory")
}
- if c.ID == 0 {
+ if c.ID <= 0 {
return errors.New("The ID is mandatory")
}
return nil
}
+// Categories represents a list of categories.
type Categories []*Category