From d24485b7b414e6066aaad5d49a1f23ac20a27ea5 Mon Sep 17 00:00:00 2001 From: stubenhuang Date: Wed, 3 Jul 2024 15:18:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20quality=E6=96=B0=E5=A2=9EmatchRuleList?= =?UTF-8?q?=E7=9A=84app=E6=8E=A5=E5=8F=A3=20#10610?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quality/api/v2/AppQualityRuleResource.kt | 38 +++++++++++++++++++ .../v2/AppQualityRuleResourceImpl.kt | 33 ++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/backend/ci/core/quality/api-quality/src/main/kotlin/com/tencent/devops/quality/api/v2/AppQualityRuleResource.kt create mode 100644 src/backend/ci/core/quality/biz-quality/src/main/kotlin/com/tencent/devops/quality/resources/v2/AppQualityRuleResourceImpl.kt diff --git a/src/backend/ci/core/quality/api-quality/src/main/kotlin/com/tencent/devops/quality/api/v2/AppQualityRuleResource.kt b/src/backend/ci/core/quality/api-quality/src/main/kotlin/com/tencent/devops/quality/api/v2/AppQualityRuleResource.kt new file mode 100644 index 00000000000..bc368a3fc8c --- /dev/null +++ b/src/backend/ci/core/quality/api-quality/src/main/kotlin/com/tencent/devops/quality/api/v2/AppQualityRuleResource.kt @@ -0,0 +1,38 @@ +package com.tencent.devops.quality.api.v2 + +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE +import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.quality.api.v2.pojo.response.QualityRuleMatchTask +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.Parameter +import io.swagger.v3.oas.annotations.tags.Tag +import javax.ws.rs.Consumes +import javax.ws.rs.GET +import javax.ws.rs.HeaderParam +import javax.ws.rs.Path +import javax.ws.rs.PathParam +import javax.ws.rs.Produces +import javax.ws.rs.QueryParam +import javax.ws.rs.core.MediaType + +@Tag(name = "USER_RULE_V2", description = "质量红线-拦截规则v2") +@Path("/app/rules/v2") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +interface AppQualityRuleResource { + @Operation(summary = "匹配拦截规则") + @Path("/{projectId}/matchRuleList") + @GET + fun matchRuleList( + @Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE) + @HeaderParam(AUTH_HEADER_USER_ID) + userId: String, + @Parameter(description = "项目ID", required = true) + @PathParam("projectId") + projectId: String, + @Parameter(description = "流水线ID", required = false, example = "1") + @QueryParam("pipelineId") + pipelineId: String + ): Result> +} diff --git a/src/backend/ci/core/quality/biz-quality/src/main/kotlin/com/tencent/devops/quality/resources/v2/AppQualityRuleResourceImpl.kt b/src/backend/ci/core/quality/biz-quality/src/main/kotlin/com/tencent/devops/quality/resources/v2/AppQualityRuleResourceImpl.kt new file mode 100644 index 00000000000..cfc524bf514 --- /dev/null +++ b/src/backend/ci/core/quality/biz-quality/src/main/kotlin/com/tencent/devops/quality/resources/v2/AppQualityRuleResourceImpl.kt @@ -0,0 +1,33 @@ +package com.tencent.devops.quality.resources.v2 + +import com.tencent.devops.common.api.exception.ParamBlankException +import com.tencent.devops.common.api.pojo.Result +import com.tencent.devops.common.web.RestResource +import com.tencent.devops.quality.api.v2.AppQualityRuleResource +import com.tencent.devops.quality.api.v2.pojo.response.QualityRuleMatchTask +import com.tencent.devops.quality.service.v2.QualityRuleCheckService +import org.springframework.beans.factory.annotation.Autowired + +@RestResource +class AppQualityRuleResourceImpl @Autowired constructor( + private val ruleCheckService: QualityRuleCheckService +) : AppQualityRuleResource { + override fun matchRuleList( + userId: String, + projectId: String, + pipelineId: String + ): Result> { + checkParam(userId, projectId) + val result = ruleCheckService.userGetMatchRuleList(projectId, pipelineId) + return Result(result) + } + + private fun checkParam(userId: String, projectId: String) { + if (userId.isBlank()) { + throw ParamBlankException("Invalid userId") + } + if (projectId.isBlank()) { + throw ParamBlankException("Invalid projectId") + } + } +}