Skip to content

Commit

Permalink
[type:fix] Fix Plugin Edit Page Issue by Correcting Plugin ID Query a…
Browse files Browse the repository at this point in the history
…nd Updating Data Type (#5622)

* [type:fix] Correct Plugin ID Query for Namespace Plugin Edit Page

* [type:fix] use @GetMapping("/{pluginId}/{namespaceId}")
  • Loading branch information
VampireAchao authored Aug 20, 2024
1 parent ce123f1 commit 429dc88
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion db/init/oracle/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (namespace(id)) */ INTO `namespace` (`id`,
CREATE TABLE plugin_ns_rel (
id VARCHAR2(128) COLLATE utf8mb4_unicode_ci NOT NULL,
namespace_id VARCHAR2(50) COLLATE utf8mb4_unicode_ci NOT NULL,
plugin_id NUMBER(11) NOT NULL,
plugin_id VARCHAR2(128) COLLATE utf8mb4_unicode_ci NOT NULL,
config CLOB COLLATE utf8mb4_unicode_ci,
sort NUMBER(11),
enabled NUMBER(4,0) NOT NULL DEFAULT 0 CHECK (enabled IN (0, 1)),
Expand Down
2 changes: 1 addition & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ INSERT INTO `shenyu`.`namespace` (`id`, `namespace_id`, `name`, `description`, `
CREATE TABLE `plugin_ns_rel` (
`id` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'primary key id',
`namespace_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'namespace id',
`plugin_id` int(11) NOT NULL COMMENT 'plugin id',
`plugin_id` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'plugin id',
`config` text COLLATE utf8mb4_unicode_ci COMMENT 'plugin configuration',
`sort` int(11) DEFAULT NULL COMMENT 'sort',
`enabled` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'whether to open (0, not open, 1 open)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.shenyu.admin.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.admin.aspect.annotation.RestApi;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
Expand Down Expand Up @@ -47,8 +49,6 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
Expand Down Expand Up @@ -103,16 +103,16 @@ public ShenyuAdminResult queryAllPlugins(@PathVariable("namespaceId")
* detail plugin of namespace.
*
* @param namespaceId namespace id.
* @param id id.
* @param pluginId pluginId.
* @return {@linkplain ShenyuAdminResult}
*/
@GetMapping("/id={id}&namespaceId={namespaceId}")
@GetMapping("/{pluginId}/{namespaceId}")
@RequiresPermissions("system:plugin:edit")
public ShenyuAdminResult detailPlugin(@PathVariable("namespaceId")
@Existed(message = "namespace is not existed", provider = NamespaceMapper.class) final String namespaceId,
@PathVariable("id")
@Existed(message = "id is not existed", provider = NamespacePluginRelMapper.class) final String id) {
NamespacePluginVO namespacePluginVO = namespacePluginService.findById(id, namespaceId);
@PathVariable("pluginId")
@Existed(message = "pluginId is not existed", provider = NamespacePluginRelMapper.class) final String pluginId) {
NamespacePluginVO namespacePluginVO = namespacePluginService.findByPluginId(pluginId, namespaceId);
return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, namespacePluginVO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public interface NamespacePluginRelMapper extends ExistProvider {
/**
* existed.
*
* @param id id
* @param pluginId pluginId
* @return existed
*/
@Override
Boolean existed(@Param("id") Serializable id);
Boolean existed(@Param("pluginId") Serializable pluginId);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public interface NamespacePluginService extends PageService<NamespacePluginQuery
String delete(List<String> ids, String namespaceId);

/**
* find plugin namespace by id.
* find plugin namespace by pluginId.
*
* @param id pk.
* @param pluginId the pluginId.
* @param namespaceId the namespaceId
* @return {@linkplain PluginVO}
*/
NamespacePluginVO findById(String id, String namespaceId);
NamespacePluginVO findByPluginId(String pluginId, String namespaceId);

/**
* find page of plugin namespace by query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public String delete(final List<String> ids, final String namespaceId) {
}

@Override
public NamespacePluginVO findById(final String id, final String namespaceId) {
return this.namespacePluginRelMapper.selectByPluginIdAndNamespaceId(id, namespaceId);
public NamespacePluginVO findByPluginId(final String pluginId, final String namespaceId) {
return this.namespacePluginRelMapper.selectByPluginIdAndNamespaceId(pluginId, namespaceId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean syncAll(final DataEventTypeEnum type) {

@Override
public boolean syncPluginData(final String pluginId, final String namespaceId) {
NamespacePluginVO namespacePluginVO = namespacePluginService.findById(pluginId, namespaceId);
NamespacePluginVO namespacePluginVO = namespacePluginService.findByPluginId(pluginId, namespaceId);
eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, DataEventTypeEnum.UPDATE,
Collections.singletonList(PluginTransfer.INSTANCE.mapToData(namespacePluginVO))));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<select id="existed" resultType="java.lang.Boolean">
SELECT true
FROM plugin_ns_rel
WHERE id = #{id} limit 1
WHERE plugin_id = #{pluginId} limit 1
</select>


Expand Down
2 changes: 1 addition & 1 deletion shenyu-admin/src/main/resources/sql-script/h2/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ INSERT IGNORE INTO `namespace` (`id`, `namespace_id`, `name`, `description`, `da
CREATE TABLE IF NOT EXISTS `plugin_ns_rel` (
`id` VARCHAR(128) NOT NULL COMMENT 'primary key id',
`namespace_id` VARCHAR(50) NOT NULL COMMENT 'namespace id',
`plugin_id` INT NOT NULL COMMENT 'plugin id',
`plugin_id` varchar(128) NOT NULL COMMENT 'plugin id',
`config` TEXT COMMENT 'plugin configuration',
`sort` INT DEFAULT NULL COMMENT 'sort',
`enabled` TINYINT NOT NULL DEFAULT 0 COMMENT 'whether to open (0, not open, 1 open)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void syncAllTest() {
public void syncPluginDataTest() {
PluginVO pluginVO = buildPluginVO();
NamespacePluginVO namespacePluginVO = new NamespacePluginVO();
given(this.namespacePluginService.findById(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(namespacePluginVO);
given(this.namespacePluginService.findByPluginId(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(namespacePluginVO);
SelectorData selectorData = buildSelectorData();
given(this.selectorService.findByPluginIdAndNamespaceId(pluginVO.getId(), SYS_DEFAULT_NAMESPACE_ID)).willReturn(Collections.singletonList(selectorData));

Expand Down

0 comments on commit 429dc88

Please sign in to comment.