Skip to content

Commit

Permalink
feature:OpenApi:支持编辑代码库 TencentBlueKing#4567
Browse files Browse the repository at this point in the history
  • Loading branch information
mingshewhe committed Jul 21, 2021
1 parent b8e0ca4 commit 2a1e932
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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("代码库列表")
Expand Down Expand Up @@ -117,4 +119,27 @@ interface ApigwRepositoryResourceV3 {
@PathParam("repositoryHashId")
repositoryHashId: String
): Result<Boolean>

@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<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> {
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -180,4 +181,21 @@ interface ServiceRepositoryResource {
@PathParam("repositoryHashId")
repositoryHashId: String
): Result<Boolean>

@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<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> {
repositoryService.userEdit(userId, projectId, repositoryHashId, repository)
return Result(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,6 @@ class UserRepositoryResourceImpl @Autowired constructor(
repositoryHashId: String,
repository: Repository
): Result<Boolean> {
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2a1e932

Please sign in to comment.