<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace Applications\sample\adminapi\controller\category;
use app\adminapi\controller\BaseAdminController;
use Applications\sample\modules\category\service\admin\CategoryService;
use Applications\sample\modules\category\validate\admin\CategoryValidator;
use Applications\sample\modules\category\validate\domain\CategoryDomainValidator;
use think\Request;
/**
 * 文章分类管理
 * Class Category
 * @package Applications\sample\adminapi\controller\category
 */
class Category extends BaseAdminController
{
    /**
     * 获取分类列表
     */
    public function list(Request $request)
    {
        return json($this->app->make(CategoryService::class)->list($request));
    }
    /**
     * 获取分类选项
     */
    public function options()
    {
        return json($this->app->make(CategoryService::class)->all());
    }
    /**
     * 获取分类详情
     */
    public function detail($id, Request $request)
    {
        return json($this->app->make(CategoryService::class)->detail((int)$id));
    }
    /**
     * 保存分类
     */
    public function save(Request $request)
    {
        $params = $request->param();
        $scene = !empty($params['id']) ? 'update' : 'create';
        $this->validate($params, CategoryValidator::class . '.' . $scene);
        $this->validateDomain($this->app->make(CategoryDomainValidator::class), $params, $scene);
        return json($this->app->make(CategoryService::class)->save($request));
    }
    /**
     * 删除分类
     */
    public function delete(Request $request)
    {
        $params = $request->post();
        $this->validate($params, CategoryValidator::class . '.delete');
        $this->validateDomain($this->app->make(CategoryDomainValidator::class), $params, 'delete');
        return json($this->app->make(CategoryService::class)->delete($request));
    }
}
