package com.ctrip.xpipe.redis.console.controller.api;

import com.ctrip.xpipe.redis.console.controller.AbstractConsoleController;
import com.ctrip.xpipe.redis.console.model.DcModel;
import com.ctrip.xpipe.redis.console.model.DcTbl;
import com.ctrip.xpipe.redis.console.service.DcService;
import com.ctrip.xpipe.spring.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author taotaotu
 * May 23, 2019
 */

@RestController
@RequestMapping(AbstractController.API_PREFIX)
public class DcApiController extends AbstractConsoleController {

    @Autowired
    private DcService dcService;

    @RequestMapping(value = "/dc", method = RequestMethod.POST)
    public RetMessage addDc(HttpServletRequest request, @RequestBody DcModel dcModel){

        logger.info("[DcApiController][addDc]request ip:{}, create a new dc, zoneId:{}, dc_name:{}, description:{}",request.getRemoteHost(),
                dcModel.getZone_id(), dcModel.getDc_name(), dcModel.getDescription());

        try {
            dcService.insertWithPartField(dcModel.getZone_id(), dcModel.getDc_name(), dcModel.getDescription());
        }catch (Exception e){
            logger.error("[DcApiController][addDc]add dc exception!", e);
            return RetMessage.createFailMessage(e.getMessage());
        }

        return RetMessage.createSuccessMessage();
    }

    @RequestMapping(value = "/dc/{dcName}", method = RequestMethod.GET)
    public DcTbl queryDcInformationByName(@PathVariable String dcName){

        return valueOrDefault(DcTbl.class, dcService.find(dcName));
    }


}

@@ -1464,227 +1464,6 @@
  %7D%0A%0A
-    @RequestMapping(value = %22/dc/%7BdcName%7D%22, method = RequestMethod.GET)%0A    public DcTbl queryDcInformationByName(@PathVariable String dcName)%7B%0A%0A        return valueOrDefault(DcTbl.class, dcService.find(dcName));%0A    %7D%0A%0A%0A
 %7D%0A

remove the conflict rest api