com.nepxion.discovery.plugin.admincenter.endpoint.GatewayStrategyRouteEndpoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-plugin-admin-center-starter Show documentation
Show all versions of discovery-plugin-admin-center-starter Show documentation
Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent
The newest version!
package com.nepxion.discovery.plugin.admincenter.endpoint;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Ning Zhang
* @author Haojun Ren
* @version 1.0
*/
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.nepxion.discovery.common.entity.GatewayStrategyRouteEntity;
import com.nepxion.discovery.common.util.ResponseUtil;
import com.nepxion.discovery.plugin.admincenter.resource.GatewayStrategyRouteResource;
@RestController
@RequestMapping(path = "/spring-cloud-gateway-route")
public class GatewayStrategyRouteEndpoint {
@Autowired
private GatewayStrategyRouteResource gatewayStrategyRouteResource;
@RequestMapping(path = "/add", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity> add(@RequestBody GatewayStrategyRouteEntity gatewayStrategyRouteEntity) {
return doAdd(gatewayStrategyRouteEntity);
}
@RequestMapping(path = "/modify", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity> modify(@RequestBody GatewayStrategyRouteEntity gatewayStrategyRouteEntity) {
return doModify(gatewayStrategyRouteEntity);
}
@RequestMapping(path = "/delete/{routeId}", method = RequestMethod.DELETE)
@ResponseBody
public ResponseEntity> delete(@PathVariable(value = "routeId") String routeId) {
return doDelete(routeId);
}
@RequestMapping(path = "/update-all", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity> updateAll(@RequestBody List gatewayStrategyRouteEntityList) {
return doUpdateAll(gatewayStrategyRouteEntityList);
}
@RequestMapping(path = "/view/{routeId}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity> view(@PathVariable(value = "routeId") String routeId) {
return doView(routeId);
}
@RequestMapping(path = "/view-all", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity> viewAll() {
return doViewAll();
}
private ResponseEntity> doAdd(GatewayStrategyRouteEntity gatewayStrategyRouteEntity) {
try {
gatewayStrategyRouteResource.add(gatewayStrategyRouteEntity);
return ResponseUtil.getSuccessResponse(true);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
private ResponseEntity> doModify(GatewayStrategyRouteEntity gatewayStrategyRouteEntity) {
try {
gatewayStrategyRouteResource.modify(gatewayStrategyRouteEntity);
return ResponseUtil.getSuccessResponse(true);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
private ResponseEntity> doDelete(String routeId) {
try {
gatewayStrategyRouteResource.delete(routeId);
return ResponseUtil.getSuccessResponse(true);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
private ResponseEntity> doUpdateAll(List gatewayStrategyRouteEntityList) {
try {
gatewayStrategyRouteResource.updateAll(gatewayStrategyRouteEntityList);
return ResponseUtil.getSuccessResponse(true);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
private ResponseEntity> doView(String routeId) {
try {
GatewayStrategyRouteEntity gatewayStrategyRouteEntity = gatewayStrategyRouteResource.view(routeId);
return ResponseUtil.getSuccessResponse(gatewayStrategyRouteEntity);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
private ResponseEntity> doViewAll() {
try {
List gatewayStrategyRouteEntityList = gatewayStrategyRouteResource.viewAll();
return ResponseUtil.getSuccessResponse(gatewayStrategyRouteEntityList);
} catch (Exception e) {
return ResponseUtil.getFailureResponse(e);
}
}
}