package cn.lihongjie.coal.dictionary.controller;

import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.dictionary.dto.CreateDictionaryItemDto;
import cn.lihongjie.coal.dictionary.dto.DictionaryItemDto;
import cn.lihongjie.coal.dictionary.dto.UpdateDictionaryItemDto;
import cn.lihongjie.coal.dictionary.service.DictionaryItemService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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("/dictionaryItem")
@RestController
@SysLog(module = "数据字典项")
public class DictionaryItemController {

    @Autowired DictionaryItemService service;

    @PostMapping("/create")
    @SysLog(action = "新增")
    public DictionaryItemDto create(@RequestBody CreateDictionaryItemDto dto) {
        return this.service.create(dto);
    }

    @PostMapping("/update")
    @SysLog(action = "编辑")
    public DictionaryItemDto update(@RequestBody UpdateDictionaryItemDto dto) {
        return this.service.update(dto);
    }

    @PostMapping("/delete")
    @SysLog(action = "删除")
    public Object delete(@RequestBody IdRequest dto) {
        this.service.delete(dto);
        return true;
    }

    @PostMapping("/list")
    public Page<DictionaryItemDto> list(@RequestBody CommonQuery dto) {
        return this.service.list(dto);
    }

    @PostMapping("/getById")
    public DictionaryItemDto getById(@RequestBody IdRequest dto) {
        return this.service.getById(dto.getId());
    }
}
