rickchengx commented on code in PR #15321: URL: https://github.com/apache/dolphinscheduler/pull/15321#discussion_r1465987042
########## dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/v2/controller/ProjectV2Controller.java: ########## @@ -0,0 +1,176 @@ +/* + * 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.v2.controller; + +import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant; +import org.apache.dolphinscheduler.api.controller.BaseController; +import org.apache.dolphinscheduler.api.dto.project.ProjectCreateRequest; +import org.apache.dolphinscheduler.api.dto.project.ProjectUpdateRequest; +import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ApiException; +import org.apache.dolphinscheduler.api.v2.annotation.Auth; +import org.apache.dolphinscheduler.api.v2.dto.QueryResult; +import org.apache.dolphinscheduler.api.v2.service.ProjectServiceV2; +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.common.enums.AuthorizationType; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.User; + +import javax.validation.Valid; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +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.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * project controller + */ +@Tag(name = "PROJECT_TAG") +@RestController +@RequestMapping("/v2/projects") +public class ProjectV2Controller extends BaseController { + + @Autowired + private ProjectServiceV2 projectService; + + /** + * create project + * + * @param loginUser login user + * @param projectCreateRequest projectCreateRequest + * @return ProjectResponse ProjectResponse + */ + @Operation(summary = "create", description = "CREATE_PROJECT_NOTES") + @PostMapping(consumes = {"application/json"}) + @ApiException(Status.CREATE_PROJECT_ERROR) + @Auth(permissionKey = ApiFuncIdentificationConstant.PROJECT_CREATE, authorizationType = AuthorizationType.PROJECTS_V2) + @ResponseStatus(HttpStatus.CREATED) + @ResponseBody + public Project createProject(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, + @Valid @RequestBody ProjectCreateRequest projectCreateRequest) { + return projectService.createProject(loginUser, projectCreateRequest.getProjectName(), + projectCreateRequest.getDescription()); + } + + /** + * update project + * + * @param loginUser login user + * @param code project code + * @param projectUpdateReq projectUpdateRequest + * @return result Result + */ + @Operation(summary = "update", description = "UPDATE_PROJECT_NOTES") + @PatchMapping(value = "/{code}", consumes = {"application/json"}) Review Comment: May I ask why use `PATCH` instead of `PUT` here, the `ProjectUpdateRequest` seems to have all the attributes of project. -- 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]
