miniflux-v2/model/category.go

56 lines
1.3 KiB
Go
Raw Normal View History

2017-11-20 06:10:04 +01:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
2018-08-25 06:51:50 +02:00
package model // import "miniflux.app/model"
2017-11-20 06:10:04 +01:00
import (
"errors"
"fmt"
)
2017-11-26 04:06:02 +01:00
// Category represents a category in the system.
2017-11-20 06:10:04 +01:00
type Category struct {
ID int64 `json:"id,omitempty"`
Title string `json:"title,omitempty"`
UserID int64 `json:"user_id,omitempty"`
FeedCount int `json:"nb_feeds,omitempty"`
}
func (c *Category) String() string {
return fmt.Sprintf("ID=%d, UserID=%d, Title=%s", c.ID, c.UserID, c.Title)
}
2017-11-26 04:06:02 +01:00
// ValidateCategoryCreation validates a category during the creation.
2017-11-20 06:10:04 +01:00
func (c Category) ValidateCategoryCreation() error {
if c.Title == "" {
return errors.New("The title is mandatory")
}
if c.UserID == 0 {
return errors.New("The userID is mandatory")
}
return nil
}
2017-11-26 04:06:02 +01:00
// ValidateCategoryModification validates a category during the modification.
2017-11-20 06:10:04 +01:00
func (c Category) ValidateCategoryModification() error {
if c.Title == "" {
return errors.New("The title is mandatory")
}
if c.UserID == 0 {
return errors.New("The userID is mandatory")
}
2017-11-26 04:06:02 +01:00
if c.ID <= 0 {
2017-11-20 06:10:04 +01:00
return errors.New("The ID is mandatory")
}
return nil
}
2017-11-26 04:06:02 +01:00
// Categories represents a list of categories.
2017-11-20 06:10:04 +01:00
type Categories []*Category