SbloodyS commented on code in PR #10832: URL: https://github.com/apache/dolphinscheduler/pull/10832#discussion_r921247516
########## dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectV2Controller.java: ########## @@ -0,0 +1,152 @@ +/* + * 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.dolphinscheduler.api.controller; + +import static org.apache.dolphinscheduler.api.enums.Status.CREATE_PROJECT_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_DETAILS_BY_CODE_ERROR; +import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_ERROR; + +import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation; +import org.apache.dolphinscheduler.api.dto.project.ProjectCreateRequest; +import org.apache.dolphinscheduler.api.dto.project.ProjectQueryRequest; +import org.apache.dolphinscheduler.api.dto.project.ProjectResponse; +import org.apache.dolphinscheduler.api.dto.project.ProjectUpdateRequest; +import org.apache.dolphinscheduler.api.exceptions.ApiException; +import org.apache.dolphinscheduler.api.service.ProjectService; +import org.apache.dolphinscheduler.api.utils.Result; +import org.apache.dolphinscheduler.common.Constants; +import org.apache.dolphinscheduler.common.utils.ParameterUtils; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import springfox.documentation.annotations.ApiIgnore; + +/** + * project controller + */ +@Api(tags = "PROJECT_TAG") +@RestController +@RequestMapping("/v2/projects") +public class ProjectV2Controller extends BaseController { + + @Autowired + private ProjectService projectService; + + /** + * create project + * + * @param loginUser login user + * @param projectCreateRequest projectCreateRequest + * @return ProjectResponse ProjectResponse + */ + @ApiOperation(value = "create", notes = "CREATE_PROJECT_NOTES") + @PostMapping(consumes = {"application/json"}) + @ResponseStatus(HttpStatus.CREATED) + @ApiException(CREATE_PROJECT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result createProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @RequestBody ProjectCreateRequest projectCreateRequest) { + Map<String, Object> result = projectService.createProject(loginUser, projectCreateRequest.getProjectName(), + projectCreateRequest.getDescription()); + return new ProjectResponse(returnDataList(result)); + } + + /** + * update project + * + * @param loginUser login user + * @param code project code + * @param projectUpdateReq projectUpdateRequest + * @return result Result + */ + @ApiOperation(value = "update", notes = "UPDATE_PROJECT_NOTES") + @PutMapping(value = "/{code}", consumes = {"application/json"}) + @ResponseStatus(HttpStatus.OK) + @ApiException(UPDATE_PROJECT_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result updateProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @PathVariable("code") Long code, + @RequestBody ProjectUpdateRequest projectUpdateReq) { + Map<String, Object> result = projectService.update(loginUser, code, projectUpdateReq.getProjectName(), + projectUpdateReq.getDescription(), projectUpdateReq.getUserName()); + return returnDataList(result); + } + + /** + * query project details by project code + * + * @param loginUser login user + * @param code project code + * @return project detail information + */ + @ApiOperation(value = "queryProjectByCode", notes = "QUERY_PROJECT_BY_ID_NOTES") + @ApiImplicitParams({ + @ApiImplicitParam(name = "code", value = "PROJECT_CODE", dataType = "Long", example = "123456") + }) + @GetMapping(value = "/{code}", consumes = {"application/json"}) + @ResponseStatus(HttpStatus.OK) + @ApiException(QUERY_PROJECT_DETAILS_BY_CODE_ERROR) + @AccessLogAnnotation(ignoreRequestArgs = "loginUser") + public Result queryProjectByCode(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @PathVariable("code") long code) { + Map<String, Object> result = projectService.queryByCode(loginUser, code); + return new ProjectResponse(returnDataList(result)); Review Comment: > rewrite projectV2Service? No need. Just optimize the existing return structure and error information. -- 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]
