package com.kiisoo.ic.tag.controller;

import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.tag.entity.TagDO;
import com.kiisoo.ic.tag.service.TagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description: 标签controller
 * @Auther: yechenhao
 * @Date: 2020/4/14 0002 21:14
 * @Version: v1
 */
@Controller
@RequestMapping("/tag")
@Slf4j
public class TagController extends BaseController {

    @Autowired
    private TagService tagService;

    /**
     * 增加标签
     * @param tagDO 标签实体类
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> addTag(@RequestBody TagDO tagDO){
        try {
            Boolean hasAdd = tagService.addTag(tagDO);
            return data(hasAdd);
        }catch (Exception e){
            log.error("添加标签失败",e);
            return fail();
        }
    }

    /**
     * 修改标签
     * @param tagDO 标签实体类
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "update",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateTag(@RequestBody TagDO tagDO){
        try {
            Boolean hasUpdate = tagService.updateTag(tagDO);
            return data(hasUpdate);
        }catch (Exception e){
            log.error("修改标签失败",e);
            return fail();
        }
    }

    /**
     * 删除标签
     * @param tagId 标签实体id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteTag(@RequestParam("tagId") Long tagId){
        try {
            Boolean hasDel = tagService.deleteTag(tagId);
            return data(hasDel);
        }catch (Exception e){
            log.error("删除标签失败",e);
            return fail();
        }
    }

//    @RequestMapping(value = "sync",method = RequestMethod.GET)
//    @ResponseBody
//    public Map<String,Object> syncTag(){
//        try {
//            Boolean hasSync = tagService.syncTag();
//            return data(hasSync);
//        }catch (Exception e){
//            log.error("添加标签失败",e);
//            return fail();
//        }
//    }
}
