class GatewayApiController {

    @PostMapping("/delete.json")
    public Result<Long> deleteApi(HttpServletRequest request, Long id) {
        AuthService.AuthUser authUser = authService.getAuthUser(request);

        if (id == null) {
            return Result.ofFail(-1, "id can't be null");
        }

        ApiDefinitionEntity oldEntity = repository.findById(id);
        if (oldEntity == null) {
            return Result.ofSuccess(null);
        }

        authUser.authTarget(oldEntity.getApp(), AuthService.PrivilegeType.DELETE_RULE);

        try {
            repository.delete(id);
        } catch (Throwable throwable) {
            logger.error("delete gateway api error:", throwable);
            return Result.ofThrowable(-1, throwable);
        }

        if (!publishApis(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort())) {
            logger.warn("publish gateway apis fail after delete");
        }

        return Result.ofSuccess(id);
    }

}