package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.es.service.IndexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author: 31966
 * @Project: mall-product
 * @Package: com.bwie.es.controller
 * @ClassName: IndexController
 * @Description: 请在此处填写具体描述
 * @Date: 2024/4/22 20:45
 */
@RestController
@RequestMapping("/index")
@Api(tags = "es索引接口")
public class IndexController {

    @Resource(name = "indexServiceImpl")
    private IndexService indexService;

    @GetMapping("/{indexName}")
    @ApiOperation(value = "查询es索引是否存在")
    public R exist(@PathVariable String indexName){
        return R.ok(indexService.exist(indexName),"es索引存在");
    }

    @GetMapping("/getMapping/{indexName}")
    @ApiOperation(value = "获取索引映射")
    public R getMapping(@PathVariable String indexName){
        return R.ok(indexService.getMapping(indexName),"索引映射存在");
    }

    @PostMapping("/{indexName}")
    @ApiOperation(value = "添加索引")
    public R index(@PathVariable String indexName,@RequestBody Map<String,Object> mappings){
        return R.ok(indexService.index(indexName,mappings),"es索引添加成功");
    }

    @PutMapping("/{indexName}")
    @ApiOperation(value = "修改索引")
    public R updateIndex(@PathVariable String indexName,@RequestBody Map<String,Object> mappings){
        return R.ok(indexService.updataIndex(indexName,mappings),"es索引修改成功");
    }

    @DeleteMapping("/{indexName}")
    @ApiOperation(value = "删除索引")
    public R deleteIndex(@PathVariable String indexName){
        return R.ok(indexService.deleteIndex(indexName),"es索引删除成功");
    }

}
