PmsSpuController.java 2.2 KB
Newer Older
郝先瑞 已提交
1 2 3 4 5 6 7 8 9
package com.youlai.mall.pms.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.form.PmsSpuForm;
import com.youlai.mall.pms.pojo.query.SpuPageQuery;
import com.youlai.mall.pms.pojo.vo.PmsSpuDetailVO;
import com.youlai.mall.pms.pojo.vo.PmsSpuPageVO;
H
haoxr 已提交
10
import com.youlai.mall.pms.service.SpuService;
郝先瑞 已提交
11 12 13 14 15 16 17
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
H
haoxr 已提交
18
 * 「管理端」商品控制层
郝先瑞 已提交
19 20 21 22
 *
 * @author haoxr
 * @date 2021/1/4
 **/
H
haoxr 已提交
23
@Api(tags = "「管理端」商品SPU接口")
郝先瑞 已提交
24 25 26 27 28
@RestController
@RequestMapping("/api/v1/spu")
@AllArgsConstructor
public class PmsSpuController {

H
haoxr 已提交
29
    private SpuService spuServiced;
郝先瑞 已提交
30 31 32

    @ApiOperation(value = "商品分页列表")
    @GetMapping("/pages")
H
hxr 已提交
33 34
    public PageResult getSpuPage(SpuPageQuery queryParams) {
        IPage<PmsSpuPageVO> result = spuServiced.getSpuPage(queryParams);
郝先瑞 已提交
35 36 37 38 39 40
        return PageResult.success(result);
    }

    @ApiOperation(value = "商品详情")
    @GetMapping("/{id}")
    public Result detail( @ApiParam("商品ID") @PathVariable Long id) {
H
haoxr 已提交
41
        PmsSpuDetailVO pmsSpuDetailVO = spuServiced.getPmsSpuDetail(id);
郝先瑞 已提交
42 43 44 45 46 47
        return Result.success(pmsSpuDetailVO);
    }

    @ApiOperation(value = "新增商品")
    @PostMapping
    public Result addSpu(@RequestBody PmsSpuForm formData) {
H
haoxr 已提交
48
        boolean result = spuServiced.addSpu(formData);
郝先瑞 已提交
49 50 51 52 53 54 55 56 57
        return Result.judge(result);
    }

    @ApiOperation(value = "修改商品")
    @PutMapping(value = "/{id}")
    public Result updateSpuById(
            @ApiParam("商品ID") @PathVariable Long id,
            @RequestBody PmsSpuForm formData
    ) {
H
haoxr 已提交
58
        boolean result = spuServiced.updateSpuById(id,formData);
郝先瑞 已提交
59 60 61 62 63 64
        return Result.judge(result);
    }

    @ApiOperation(value = "删除商品")
    @DeleteMapping("/{ids}")
    public Result delete(@ApiParam("商品ID,多个以英文逗号(,)分隔") @PathVariable String ids) {
H
haoxr 已提交
65
        boolean result = spuServiced.removeBySpuIds(ids);
郝先瑞 已提交
66 67 68 69
        return Result.judge(result);
    }

}