From 2a1e932a6a330abcc8c8b56f89292197d9e4cf7f Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Wed, 21 Jul 2021 14:35:16 +0800 Subject: [PATCH] =?UTF-8?q?feature=EF=BC=9AOpenApi=EF=BC=9A=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=BC=96=E8=BE=91=E4=BB=A3=E7=A0=81=E5=BA=93=20#4567?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/apigw/v3/ApigwRepositoryResourceV3.kt | 25 +++++++++++++++++++ .../apigw/v3/ApigwRepositoryResourceV3Impl.kt | 19 ++++++++++++++ .../api/ServiceRepositoryResource.kt | 18 +++++++++++++ .../ServiceRepositoryResourceImpl.kt | 10 ++++++++ .../resources/UserRepositoryResourceImpl.kt | 15 ----------- .../repository/service/RepositoryService.kt | 16 ++++++++++++ 6 files changed, 88 insertions(+), 15 deletions(-) diff --git a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v3/ApigwRepositoryResourceV3.kt b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v3/ApigwRepositoryResourceV3.kt index 9bbd1f038b4..0e7de3e56f5 100644 --- a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v3/ApigwRepositoryResourceV3.kt +++ b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v3/ApigwRepositoryResourceV3.kt @@ -44,6 +44,7 @@ import javax.ws.rs.DELETE import javax.ws.rs.GET import javax.ws.rs.HeaderParam import javax.ws.rs.POST +import javax.ws.rs.PUT import javax.ws.rs.Path import javax.ws.rs.PathParam import javax.ws.rs.Produces @@ -54,6 +55,7 @@ import javax.ws.rs.core.MediaType @Path("/{apigwType:apigw-user|apigw-app|apigw}/v3/repositories") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) +@SuppressWarnings("All") interface ApigwRepositoryResourceV3 { @ApiOperation("代码库列表") @@ -117,4 +119,27 @@ interface ApigwRepositoryResourceV3 { @PathParam("repositoryHashId") repositoryHashId: String ): Result + + @ApiOperation("编辑关联代码库") + @PUT + @Path("/{projectId}/{repositoryHashId}/") + fun edit( + @ApiParam(value = "appCode", required = true, defaultValue = AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_DEVOPS_APP_CODE) + appCode: String?, + @ApiParam(value = "apigw Type", required = true) + @PathParam("apigwType") + apigwType: String?, + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_DEVOPS_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_DEVOPS_USER_ID) + userId: String, + @ApiParam("项目ID", required = true) + @PathParam("projectId") + projectId: String, + @ApiParam("代码库哈希ID", required = true) + @PathParam("repositoryHashId") + repositoryHashId: String, + @ApiParam(value = "代码库模型", required = true) + repository: Repository + ): Result } diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwRepositoryResourceV3Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwRepositoryResourceV3Impl.kt index 193d80b9629..b7b12f20677 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwRepositoryResourceV3Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v3/ApigwRepositoryResourceV3Impl.kt @@ -92,6 +92,25 @@ class ApigwRepositoryResourceV3Impl @Autowired constructor(private val client: C ) } + override fun edit( + appCode: String?, + apigwType: String?, + userId: String, + projectId: String, + repositoryHashId: String, + repository: Repository + ): Result { + logger.info( + "edit repostitories in project:userId=$userId,projectId=$projectId,repositoryHashId:$repositoryHashId" + ) + return client.get(ServiceRepositoryResource::class).edit( + userId = userId, + projectId = projectId, + repositoryHashId = repositoryHashId, + repository = repository + ) + } + companion object { private val logger = LoggerFactory.getLogger(ApigwRepositoryResourceV3Impl::class.java) } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryResource.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryResource.kt index e30033f8e39..8996b9a224a 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryResource.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/ServiceRepositoryResource.kt @@ -46,6 +46,7 @@ import javax.ws.rs.DELETE import javax.ws.rs.GET import javax.ws.rs.HeaderParam import javax.ws.rs.POST +import javax.ws.rs.PUT import javax.ws.rs.Path import javax.ws.rs.PathParam import javax.ws.rs.Produces @@ -180,4 +181,21 @@ interface ServiceRepositoryResource { @PathParam("repositoryHashId") repositoryHashId: String ): Result + + @ApiOperation("编辑关联代码库") + @PUT + @Path("/{projectId}/{repositoryHashId}/") + fun edit( + @ApiParam(value = "用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @ApiParam("项目ID", required = true) + @PathParam("projectId") + projectId: String, + @ApiParam("代码库哈希ID", required = true) + @PathParam("repositoryHashId") + repositoryHashId: String, + @ApiParam(value = "代码库模型", required = true) + repository: Repository + ): Result } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryResourceImpl.kt index 4245b68960f..f6c6c6d5cc8 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/ServiceRepositoryResourceImpl.kt @@ -172,4 +172,14 @@ class ServiceRepositoryResourceImpl @Autowired constructor( repositoryService.userDelete(userId, projectId, repositoryHashId) return Result(true) } + + override fun edit( + userId: String, + projectId: String, + repositoryHashId: String, + repository: Repository + ): Result { + repositoryService.userEdit(userId, projectId, repositoryHashId, repository) + return Result(true) + } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryResourceImpl.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryResourceImpl.kt index ef6918bf6d2..99a4bd93995 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryResourceImpl.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/resources/UserRepositoryResourceImpl.kt @@ -123,21 +123,6 @@ class UserRepositoryResourceImpl @Autowired constructor( repositoryHashId: String, repository: Repository ): Result { - if (userId.isBlank()) { - throw ParamBlankException("Invalid userId") - } - if (projectId.isBlank()) { - throw ParamBlankException("Invalid projectId") - } - if (repositoryHashId.isBlank()) { - throw ParamBlankException("Invalid repositoryHashId") - } - if (repository.aliasName.isBlank()) { - throw ParamBlankException("Invalid repository aliasName") - } - if (repository.url.isBlank()) { - throw ParamBlankException("Invalid repository url") - } repositoryService.userEdit(userId, projectId, repositoryHashId, repository) return Result(true) } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryService.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryService.kt index b5ee0e8ae97..7ea1f77b77d 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryService.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/service/RepositoryService.kt @@ -35,6 +35,7 @@ import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.enums.ScmType import com.tencent.devops.common.api.exception.ErrorCodeException import com.tencent.devops.common.api.exception.OperationException +import com.tencent.devops.common.api.exception.ParamBlankException import com.tencent.devops.common.api.exception.PermissionForbiddenException import com.tencent.devops.common.api.exception.RemoteServiceException import com.tencent.devops.common.api.model.SQLPage @@ -710,6 +711,21 @@ class RepositoryService @Autowired constructor( } fun userEdit(userId: String, projectId: String, repositoryHashId: String, repository: Repository) { + if (userId.isBlank()) { + throw ParamBlankException("Invalid userId") + } + if (projectId.isBlank()) { + throw ParamBlankException("Invalid projectId") + } + if (repositoryHashId.isBlank()) { + throw ParamBlankException("Invalid repositoryHashId") + } + if (repository.aliasName.isBlank()) { + throw ParamBlankException("Invalid repository aliasName") + } + if (repository.url.isBlank()) { + throw ParamBlankException("Invalid repository url") + } val repositoryId = HashUtil.decodeOtherIdToLong(repositoryHashId) validatePermission( user = userId,