package shop.alien.store.controller;

import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.LifeDict;
import shop.alien.entity.store.vo.StoreDictionaryVo;
import shop.alien.store.service.LifeDictService;

import java.util.List;

/**
 * 字典
 */
@Api(tags = {"一期-字典"})
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/dicts")
@RequiredArgsConstructor
public class LifeDictController {

    private final LifeDictService lifeDictService;

    @ApiOperation("查询字典")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({@ApiImplicitParam(name = "typeName", value = "类型名称", dataType = "String", paramType = "query")})
    @GetMapping("/getLifeDictByTypeName")
    public R<List<StoreDictionaryVo>> getLifeDictByTypeName(@RequestParam(required = false) String typeName) {
        log.info("LifeDictController.getLifeDictByTypeName?id={}", typeName);
        return R.data(lifeDictService.getLifeDictByTypeName(typeName));
    }

    @PostMapping("/addDict")
    public int addDict(@RequestBody LifeDict lifeDict) {
        log.info("LifeDictController.addDict?request={}", lifeDict.toString());
        return lifeDictService.addLifeDict(lifeDict);
    }

    @PostMapping("/delete")
    public int delete(@RequestBody LifeDict lifeDict) {
        log.info("LifeDictController.delete?request={}", lifeDict.toString());
        return lifeDictService.deleteLifeDict(lifeDict);
    }
}
 