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