rentaiming
2024-05-27 43c263df4d8ce0cc830f287780c29db8a2b47f0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.ruoyi.goods.controller.management;
 
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.goods.controller.management.dto.GoodsCategoryDTO;
import com.ruoyi.goods.controller.management.dto.GoodsCategoryQuery;
import com.ruoyi.goods.controller.management.vo.GoodsCategoryVO;
import com.ruoyi.goods.service.IGoodsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;
 
/**
 * <p>
 * 商品分类表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-05-16
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/mgt/goods-category")
@Api(value = "管理后台商品分类相关接口", tags = {"管理后台接口"})
public class MgtGoodsCategoryController {
 
    private final IGoodsCategoryService goodsCategoryService;
 
    /**
     * 获取商品分类列表的分页数据
     *
     * @param query 商品分类查询条件,通过RequestBody接收前端传来的查询参数。
     * @return 返回一个包含商品分类分页数据的结果对象,其中数据部分为PageDTO<GoodsCategoryVO>类型。
     */
    @ApiOperation(value = " 获取商品分类列表的分页数据", notes = " 获取商品分类列表的分页数据")
    @PostMapping("/page")
    public R<PageDTO<GoodsCategoryVO>> getGoodsCategoryPage(
            @Validated @RequestBody GoodsCategoryQuery query) {
        return R.ok(goodsCategoryService.getGoodsCategoryPage(query));
    }
 
    /**
     * 新增/编辑商品分类。 该接口用于接收前端发送的商品分类数据,通过商品分类数据传输对象(GoodsCategoryDTO)来新增或编辑商品分类信息。
     *
     * @param dto 商品分类数据传输对象,包含商品分类的详细信息,通过RequestBody接收。 使用@Validated注解进行参数验证,确保数据的完整性和正确性。
     * @return 返回操作结果,使用R<Void>作为返回类型,其中R是自定义的结果封装类,Void表示操作不返回具体数据。 如果操作成功,返回R.ok(),表示操作成功。
     */
    @ApiOperation(value = "新增/编辑 商品分类", notes = "新增/编辑 商品分类")
    @PostMapping("/save")
    public R<Void> saveGoodsCategory(@Validated @RequestBody GoodsCategoryDTO dto) {
        goodsCategoryService.saveGoodsCategory(dto);
        return R.ok();
    }
 
    /**
     * 删除商品分类
     *
     * @param id 商品分类的唯一标识符
     * @return 返回操作结果,如果操作成功,则返回一个成功的标识
     */
    @ApiOperation(value = "删除商品分类", notes = "删除商品分类")
    @DeleteMapping("/{id}")
    public R<Void> deleteGoodsCategory(@Validated @PathVariable("id") Long id) {
        goodsCategoryService.removeById(id);
        return R.ok();
    }
}