macksonmu commented on code in PR #1831: URL: https://github.com/apache/incubator-streampark/pull/1831#discussion_r996378738
########## streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/VariableController.java: ########## @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.streampark.console.system.controller; + +import org.apache.streampark.console.base.domain.RestRequest; +import org.apache.streampark.console.base.domain.RestResponse; +import org.apache.streampark.console.system.entity.Variable; +import org.apache.streampark.console.system.service.VariableService; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; +import javax.validation.constraints.NotBlank; + +@Slf4j +@Validated +@RestController +@RequestMapping("variable") +public class VariableController { + + @Autowired + private VariableService variableService; + + @PostMapping("list") + @RequiresPermissions("variable:view") + public RestResponse variableList(RestRequest restRequest, Variable variable) { + IPage<Variable> variableList = variableService.findVariables(variable, restRequest); + return RestResponse.success(variableList); + } + + @PostMapping("post") + @RequiresPermissions("variable:add") + public RestResponse addVariable(@Valid Variable variable) throws Exception { + this.variableService.createVariable(variable); + return RestResponse.success(); + } + + @PutMapping("update") + @RequiresPermissions("variable:update") + public RestResponse updateVariable(@Valid Variable variable) throws Exception { + this.variableService.updateById(variable); Review Comment: @wolfboys Is the following code logic possible? @PutMapping("update") @RequiresPermissions("variable:update") public RestResponse updateVariable(@Valid Variable variable) throws Exception { if (variable.getId() == null) { throw new ApiAlertException("Sorry, the variable id cannot be null."); } Variable findVariable = this.variableService.getById(variable.getId()); if (findVariable == null) { throw new ApiAlertException("Sorry, the variable does not exist."); } if (!findVariable.getVariableCode().equals(variable.getVariableCode())) { throw new ApiAlertException("Sorry, the variable code cannot be updated."); } this.variableService.updateById(variable); return RestResponse.success(); } -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
