aboutsummaryrefslogtreecommitdiffhomepage
path: root/model/category.go
blob: 76f254fb8c9fd452b8c34dfc6ae0c6a33be51dbf (plain)
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
// 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"
)

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)
}

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
}

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
}

type Categories []*Category