summaryrefslogtreecommitdiff
path: root/model/category.go
blob: 1c72851b419fe8e9439a6cdc3fbe7a8b1038b80c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 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.

package model

import (
	"errors"
	"fmt"
)

// Category represents a category in the system.
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)
}

// ValidateCategoryCreation validates a category during the creation.
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
}

// ValidateCategoryModification validates a category during the modification.
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")
	}

	if c.ID <= 0 {
		return errors.New("The ID is mandatory")
	}

	return nil
}

// Categories represents a list of categories.
type Categories []*Category
c='//www.gravatar.com/avatar/13cf34712525e2848d4468120b95674e?s=13&d=retro' width='13' height='13' alt='Gravatar' /> Ruslan Drozhdzh 1-0/+5 2018-05-18add dup endpoint name test (#1811)Gravatar Chris O'Haver 1-6/+30 2018-05-18reload: don't fail test on addr in use (#1804)Gravatar Miek Gieben 1-1/+9 2018-05-17Fix typo in erratic.go (#1812)Gravatar Anton Antonov 1-1/+1 2018-05-17Update kubernetes/client-go to v7.0.0 (#1808)Gravatar Yong Tang 730-43138/+17318 2018-05-16golinter fix (#1807)Gravatar Yong Tang 1-2/+2 2018-05-16Vendor update with github.com/ugorji/go and github.com/apache/thrift pinning ...Gravatar Yong Tang 10682-4047998/+37388 2018-05-16Dep ensure (#1803)Gravatar Miek Gieben 10377-54910/+4225825 2018-05-16Probe simplification (#1784)Gravatar Ruslan Drozhdzh 1-49/+42 2018-05-15plugin/tls: make CA parameter optional (#1800)Gravatar Ruslan Drozhdzh 2-3/+5 2018-05-11plugin/reload: mention auto in reload (#1793)Gravatar Chris O'Haver 1-0/+3 2018-05-11plugin/proxy: fix except example (#1796)Gravatar Chris O'Haver 1-1/+1 2018-05-11Try to clarify rewrite docs (#1795)Gravatar Chris O'Haver 1-13/+19 2018-05-10Up miekg/dns to 1.0.6 (#1792)Gravatar Miek Gieben 1-1/+1