package com.yx.face.controller.admin;

import com.yx.face.boot.restful.RestResponse;
import com.yx.face.boot.restful.RestResult;
import com.yx.face.model.entity.AdminTag;
import com.yx.face.model.vo.AdminTagVO;
import com.yx.face.service.AdminTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @ClassName TagController
 * @Author WXG
 * @Date 2021/11/9 11:44
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "B 标签管理 API")
@RestController
@RequestMapping("admin/tag")
public class AdminTagController {
    private final AdminTagService adminTagService;

    @ApiOperation("新增标签")
    @PostMapping("insert")
    public RestResult<Boolean> insert(@RequestBody AdminTag adminTag) {
        Integer insert = adminTagService.insert(adminTag);
        if (insert == 1) return RestResponse.ok(true);
        else return RestResponse.error("增加失败");
    }

    @ApiOperation("修改标签")
    @PostMapping("update")
    public RestResult<Boolean> update(@RequestBody AdminTag adminTag) {
        Integer insert = adminTagService.update(adminTag);
        if (insert == 1) return RestResponse.ok(true);
        else return RestResponse.error("修改失败");
    }

    @ApiOperation("删除标签")
    @GetMapping("delete")
    public RestResult<Boolean> delete(@RequestParam("tagId") Integer id) {
        Integer insert = adminTagService.delete(id);
        if (insert == 1) return RestResponse.ok(true);
        else return RestResponse.error("删除失败");
    }

    @ApiOperation("标签列表")
    @GetMapping("/getList")
    public RestResult<List<AdminTagVO>> getList(@RequestParam(value = "provinceId", required = false) Integer provinceId) {
        List<AdminTagVO> list = adminTagService.getList(provinceId);
        if (list != null) {
            return RestResponse.ok(list);
        }
        return RestResponse.error("获取标签列表失败");
    }
}
