审查视图

pkg/application/evaluation_template/command/template_create.go 965 字节
1 2 3 4
package command

import (
	"github.com/beego/beego/v2/core/validation"
郑周 authored
5
	"unicode/utf8"
6 7 8 9 10 11
)

type CreateTemplateCommand struct {
	CompanyId int64  `cname:"公司ID" json:"companyId"`
	CreatorId int64  `cname:"创建人ID" json:"creatorId"`
	Name      string `cname:"模板名称" json:"name" valid:"Required"`
12
	Describe  string `cname:"模板描述" json:"describe"`
13 14 15 16 17 18 19 20 21 22 23 24
}

func (in *CreateTemplateCommand) Valid(validation *validation.Validation) {
	if in.CompanyId == 0 {
		validation.SetError("companyId", "公司ID无效")
		return
	}
	if in.CreatorId == 0 {
		validation.SetError("creatorId", "创建人ID无效")
		return
	}
郑周 authored
25 26
	// 这个才是真正计算字符串文字长度的 utf8.RuneCountInString(in.Name)
	if utf8.RuneCountInString(in.Name) > 40 {
27 28 29
		validation.SetError("name", "模板名称最大长度40个字符")
		return
	}
30
郑周 authored
31
	if utf8.RuneCountInString(in.Describe) > 100 {
32 33 34
		validation.SetError("describe", "备注最大长度100个字符")
		return
	}
35
}