package com.jfinal.club.my.ques;

import com.jfinal.club.common.model.Questions;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.validate.Validator;

/**
 * @ProjectName: jfinal-club
 * @Package: com.jfinal.club.my.ques
 * @ClassName: QuestionsValidator
 * @Author: Jzdsh
 * @Description:
 * @Date: 2020/3/31 11:06
 * @Version: 1.0
 */
public class QuestionsValidator extends Validator {

    @Override
    protected void validate(Controller c) {
        setShortCircuit(true);
        setRet(Ret.fail( ));
        c.getFile("filepath", "/temp");
        validateRequired("questions.quesname", "msg", "请填写问题描述！");
       /* validateRequired("questions.questext", "msg", "请填写问题补充说明！");*/

        String ms = c.get("questions.quesname");
        String sm = c.get("questions.questext");
        if (ms.length( ) > 200) {
            addError("msg", "问题描述应该小于200个字符!");
        }
        if (sm != null && sm.length( ) > 5000) {
            addError("msg", "问题补充应不大于5000字符");
        }

    }

    @Override
    protected void handleError(Controller c) {
        c.keepModel(Questions.class);
        c.renderJson(getRet( ));
    }
}
