MCPcopy Index your code
hub / github.com/TruthHun/BookStack / AddCates

Method AddCates

models/category.go:41–61  ·  view source on GitHub ↗

新增分类

(pid int, cates string)

Source from the content-addressed store, hash-verified

39
40//新增分类
41func (this *Category) AddCates(pid int, cates string) (err error) {
42 slice := strings.Split(cates, "\n")
43 if len(slice) == 0 {
44 return
45 }
46
47 o := orm.NewOrm()
48 for _, item := range slice {
49 if item = strings.TrimSpace(item); item != "" {
50 var cate = Category{
51 Pid: pid,
52 Title: item,
53 Status: true,
54 }
55 if cnt, _ := o.QueryTable(this).Filter("title", cate.Title).Filter("pid", cate.Pid).Count(); cnt == 0 {
56 _, err = orm.NewOrm().Insert(&cate)
57 }
58 }
59 }
60 return
61}
62
63//删除分类(如果分类下的书籍不为0,则不允许删除)
64func (this *Category) Del(id int) (err error) {

Callers 1

CategoryMethod · 0.80

Calls 2

CountMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected