package com.jfinal.club.my.ct;

import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;
import com.jfinal.validate.Validator;

/**
 * @ClassName UsersValidator
 * @Description TODO
 * @Author caolong
 * @Date 2020/3/17 17:44
 */
public class UserCtValidator extends Validator {


    @Override
    protected void validate(Controller c) {
        //lc 2020.3.30 modified
        setShortCircuit(true);
        setRet(Ret.fail());
        c.getFile("filepath", "/temp");

        validateRequired("userct.ctname", "msg", "词条名称不能为空");
/*        validateRequired("userct.cttext", "msg", "词条概述信息不能为空");
        validateRequired("userct.ctcontext", "msg", "词条详情不能为空")*/;
        String name = c.get("userct.ctname");
        if(name.length() > 50){
            addError("msg","词条名称请控制在50个字以内");
        }
        String cttext = c.get("userct.cttext");
        if(cttext != null && cttext.length() > 5000){
            addError("msg","词条概述请控制在5000字以内");
        }

    }

    @Override
    protected void handleError(Controller c) {
        Ret ret = getRet();
        c.renderJson(ret);
    }
}
