package com.cslg.ppa.controller;

import com.cslg.ppa.common.core.auth.Response;
import com.cslg.ppa.common.core.base.Constants;
import com.cslg.ppa.dto.*;
import com.cslg.ppa.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(Constants.API_PPA + "/category")
@RestController
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Operation(summary = "查询类别列表")
    @PostMapping("/selectCategoryList")
    public String selectCategoryList(@RequestBody SelectCategoryListDTO vo) {
        return categoryService.selectCategoryList(vo);
    }

    @Operation(summary = "新增或编辑类别信息")
    @PostMapping("/addOrEditCategory")
    public String addOrEditCategory(@RequestBody CategoryDTO vo) {
        final Integer id = categoryService.addOrEditCategory(vo);
        return Response.success(id);
    }

    @Operation(summary = "删除类别信息")
    @PostMapping("/deleteCategory")
    public String deleteCategory(@RequestBody CategoryIdDTO vo) {
        categoryService.deleteCategory(vo);
        return Response.success("删除成功");
    }
}
