read_notice.go 828 字节
package command

import (
	"fmt"

	"github.com/beego/beego/v2/core/validation"
)

type ReadNoticeCommand struct {
	UserBaseId int  `json:"userBaseId"` //读取谁的消息读
	NoticeId   int  `json:"noticeId"`   //消息id
	ReadAll    bool `json:"readAll"`    //是否全部标记为已读
}

func (readNoticeCommand *ReadNoticeCommand) Valid(validation *validation.Validation) {
	if !readNoticeCommand.ReadAll {
		if readNoticeCommand.UserBaseId <= 0 {
			validation.AddError("userBaseId", "未填写")
		}
	}
}

func (readNoticeCommand *ReadNoticeCommand) ValidateCommand() error {
	valid := validation.Validation{}
	b, err := valid.Valid(readNoticeCommand)
	if err != nil {
		return err
	}
	if !b {
		for _, validErr := range valid.Errors {
			return fmt.Errorf("%s  %s", validErr.Key, validErr.Message)
		}
	}
	return nil
}