package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysAppletIndexCategoriesBo;
import org.dromara.system.domain.vo.SysAppletIndexCategoriesVo;
import org.dromara.system.service.ISysAppletIndexCategoriesService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序首页精选分类管理
 *
 * @Author: Trae
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/applet/categories")
public class SysAppletIndexCategoriesController extends BaseController {

    private final ISysAppletIndexCategoriesService categoriesService;

    /**
     * 查询全部精选分类
     */
    @SaIgnore
    @GetMapping("/list")
    public R<List<SysAppletIndexCategoriesVo>> list() {
        return R.ok(categoriesService.queryAll());
    }

    /**
     * 根据ID查询分类
     */
    @SaIgnore
    @GetMapping("/{id}")
    public R<SysAppletIndexCategoriesVo> getById(@PathVariable Long id) {
        return R.ok(categoriesService.queryById(id));
    }

    /**
     * 修改分类
     */
    @Log(title = "精选分类管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysAppletIndexCategoriesBo bo) {
        categoriesService.updateByBo(bo);
        return R.ok();
    }

}
