package com.persagy.dmp.codetable.controller;

import cn.hutool.core.util.StrUtil;
import com.persagy.dmp.codetable.entity.CodeTableData;
import com.persagy.dmp.codetable.service.ICodeTableDataService;
import com.persagy.dmp.common.context.AppContext;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.common.utils.ResultHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 码表数据 Controller
 * @author Charlie Yu
 * @date 2021-07-27
 */
@RestController
@RequestMapping(value = "/dic/code/")
public class CodeTableDataController {

    @Autowired
    private ICodeTableDataService dataService;

    /**
     * 根据码表类型查询所有字典数据
     * @param typeCode 码表类型编码
     * @return List<CodeTableDetail>
     */
    @GetMapping("/queryAll/{typeCode}")
    public CommonResult<List<CodeTableData>> queryCodeTableDetailListByCodeTableId(@PathVariable String typeCode) {
        if (StrUtil.isBlank(typeCode)) {
            return null;
        }
        List<CodeTableData> dataList = dataService.queryAllByTypeCode(AppContext.getContext().getProjectId(), typeCode);
        return ResultHelper.multi(dataList);
    }
}
