package shop.alien.second.platform;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.second.SecondGoodsCategory;
import shop.alien.second.service.SecondGoodsCategoryService;

@Slf4j
@Api(tags = {"二手平台-商品类型"})
@ApiSort(9)
@CrossOrigin
@RestController
@RequestMapping("/second/goodsCategory")
@RequiredArgsConstructor
public class PlatformSecondCategoryController {

    private final SecondGoodsCategoryService service;

    @ApiOperation("新增商品类型")
    @PostMapping("/insertSecondGoodsCategory")
    public R<String> insertSecondGoodsCategory(@RequestBody SecondGoodsCategory category) throws Exception {
        log.info("SecondGoodsCategoryController.insertSecondGoodsCategory?category={}", category.toString());
        Integer reporting = service.insertSecondGoodsCategory(category);
        if (0 == reporting) {
            return R.fail("新增商品类型失败");
        } else {
            return R.data("新增商品类型成功");
        }
    }

    @ApiOperation("修改商品类型")
    @PostMapping("/updateSecondGoodsCategory")
    public R<String> updateSecondGoodsCategory(@RequestBody SecondGoodsCategory category) throws Exception  {
        log.info("SecondGoodsCategoryController.updateSecondGoodsCategory?category={}", category.toString());
        Integer reporting = service.updateSecondGoodsCategory(category);
        if (0 == reporting) {
            return R.fail("修改商品类型失败");
        } else {
            return R.data("修改商品类型成功");
        }
    }
}
