BlogLabelController.php 2.7 KB
<?php

namespace App\Http\Controllers\Bside\Blog;

use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Blog\BlogLabelLogic;
use App\Http\Requests\Bside\Blog\BlogLabelRequest;
use App\Models\Blog\BlogLabel as BlogLabelModel;

class BlogLabelController extends BaseController
{
    /**
     * @name :博客标签列表
     * @author :liyuhang
     * @method
     */
    public function lists(BlogLabelModel $blogLabelModel){
        $this->map['project_id'] = $this->user['project_id'];
        $lists = $blogLabelModel->lists($this->map,$this->page,$this->row,$this->order,['id','name','created_at','updated_at']);
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @name :添加标签
     * @return void
     * @author :liyuhang
     * @method
     */
    public function add(BlogLabelRequest $request,BlogLabelLogic $blogLabelLogic){
        $request->validated();
        $data = $blogLabelLogic->add_blog_label();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :批量添加
     * @name   :batchAdd
     * @author :lyh
     * @method :post
     * @time   :2023/8/28 14:25
     */
    public function batchAdd(BlogLabelLogic $logic){
        $this->request->validate([
            'name'=>['required','array']
        ],[
            'name.required' => 'name不能为空',
            'name.array' => 'name为数组'
        ]);
        $data = $logic->batchAdd();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @name :编辑标签
     * @author :liyuhang
     * @method
     */
    public function edit(BlogLabelRequest $request,BlogLabelLogic $blogLabelLogic){
        $request->validate([
            'id'=>['required']
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $data = $blogLabelLogic->edit_blog_label();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @name :编辑标签状态/排序
     * @author :liyuhang
     * @method
     */
    public function status(BlogLabelLogic $blogLabelLogic){
        $this->request->validate([
            'id'=>['required'],
        ],[
            'id.required' => 'ID不能为空',
        ]);
        $blogLabelLogic->status_blog_label();
        $this->response('success');
    }

    /**
     * @name :删除标签(批量删除)
     * @author :liyuhang
     * @method
     */
    public function del(BlogLabelLogic $blogLabelLogic){
        $this->request->validate([
            'id'=>['required','array'],
        ],[
            'id.required' => 'ID不能为空',
            'id.array' => 'ID为数组',
        ]);
        $blogLabelLogic->del_blog_label();
        $this->response('success');
    }
}