fun banPackage()

in core/project/src/main/kotlin/io/klibs/core/project/blacklist/BlacklistController.kt [20:55]


    fun banPackage(
        @RequestParam(name = "groupId")
        @Parameter(
            description = "Group ID of the Maven artifact",
            example = "org.danbrough.ktor"
        )
        groupId: String,

        @RequestParam(name = "artifactId", required = false)
        @Parameter(
            description = "Artifact ID of the Maven artifact",
            example = "ktor-client"
        )
        artifactId: String?,

        @RequestParam(name = "reason", required = false)
        @Parameter(
            description = "Reason for the blacklisting",
            example = "Malicious package"
        )
        reason: String?

    ): ResponseEntity<String> {
        val actualReason = reason?.takeIf { it.isNotBlank() }
        val success = if (artifactId != null) {
            blacklistService.banPackage(groupId, artifactId, actualReason)
        } else {
            blacklistService.banByGroup(groupId, actualReason)
        }

        return if (success) {
            ResponseEntity.ok("Package $groupId:$artifactId has been banned successfully")
        } else {
            ResponseEntity.badRequest().body("Failed to ban package $groupId:$artifactId. It might not exist or is already banned.")
        }
    }