Search in sources :

Example 1 with CommonResponse

use of io.github.tesla.ops.common.CommonResponse in project tesla by linking12.

the class FilterRouteController method save.

@Log("保存路由")
@RequiresPermissions("filter:route:add")
@PostMapping("/save")
@ResponseBody()
public CommonResponse save(RouteVo zuulVo, @RequestParam(name = "zipFile", required = false) MultipartFile zipFile) {
    try {
        // grpc路由
        if (zipFile != null) {
            InputStream directoryZipStream = zipFile.getInputStream();
            CommonResponse response = judgeFileType(directoryZipStream, "zip");
            if (response != null) {
                return response;
            } else {
                String serviceFileName = zuulVo.getServiceFileName();
                byte[] protoContext = protobufService.compileDirectoryProto(zipFile, serviceFileName);
                FilterRouteDto zuulDto = zuulVo.buildRouteDto();
                zuulDto.setProtoContext(protoContext);
                routeService.save(zuulDto);
            }
        } else {
            FilterRouteDto zuulDto = zuulVo.buildRouteDto();
            routeService.save(zuulDto);
        }
    } catch (IOException e) {
        throw new TeslaException("保存路由失败", e);
    }
    return CommonResponse.ok();
}
Also used : InputStream(java.io.InputStream) FilterRouteDto(io.github.tesla.ops.filter.dto.FilterRouteDto) IOException(java.io.IOException) CommonResponse(io.github.tesla.ops.common.CommonResponse) TeslaException(io.github.tesla.ops.common.TeslaException) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(io.github.tesla.ops.common.Log) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with CommonResponse

use of io.github.tesla.ops.common.CommonResponse in project tesla by linking12.

the class FilterRouteController method update.

@Log("更新路由")
@RequiresPermissions("filter:route:edit")
@PostMapping("/update")
@ResponseBody()
public CommonResponse update(RouteVo zuulVo, @RequestParam(name = "zipFile", required = false) MultipartFile zipFile) {
    try {
        // grpc路由
        if (zipFile != null) {
            InputStream directoryZipStream = zipFile.getInputStream();
            CommonResponse response = judgeFileType(directoryZipStream, "zip");
            if (response != null) {
                return response;
            } else {
                String serviceFileName = zuulVo.getServiceFileName();
                byte[] protoContext = protobufService.compileDirectoryProto(zipFile, serviceFileName);
                FilterRouteDto zuulDto = zuulVo.buildRouteDto();
                zuulDto.setProtoContext(protoContext);
                routeService.update(zuulDto);
            }
        } else {
            FilterRouteDto zuulDto = zuulVo.buildRouteDto();
            routeService.update(zuulDto);
        }
    } catch (IOException e) {
        throw new TeslaException("保存路由失败", e);
    }
    return CommonResponse.ok();
}
Also used : InputStream(java.io.InputStream) FilterRouteDto(io.github.tesla.ops.filter.dto.FilterRouteDto) IOException(java.io.IOException) CommonResponse(io.github.tesla.ops.common.CommonResponse) TeslaException(io.github.tesla.ops.common.TeslaException) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(io.github.tesla.ops.common.Log) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

CommonResponse (io.github.tesla.ops.common.CommonResponse)2 Log (io.github.tesla.ops.common.Log)2 TeslaException (io.github.tesla.ops.common.TeslaException)2 FilterRouteDto (io.github.tesla.ops.filter.dto.FilterRouteDto)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2