<?php

namespace app\admin\controller;

use app\admin\logic\VersionLogic;
use app\BaseController;
use think\exception\ValidateException;
use think\facade\Config;
use think\facade\Validate;

class Version extends BaseController
{
    //最新版本信息
    public function lastVersion()
    {
        return VersionLogic::lastVersion();
    }

    //获取版本列表
    public function getList()
    {
        $param = $this->request->only(['page' => 1, 'size' => 10, 'keyword' => ''], 'post');
        $val = Validate::rule(Config::get('validate_rules.common'));
        if (!$val->check($param)) throw new ValidateException($val->getError());

        return VersionLogic::getList($param);
    }

    //创建版本
    public function create()
    {
        $param = $this->request->only(['title', 'content', 'version'], 'post');
        $val = Validate::rule(Config::get('validate_rules.createVersion'));

        if (!$val->check($param)) throw new ValidateException($val->getError());
        return VersionLogic::create($param);
    }

}