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") + } + } +}