nzomkxia closed pull request #123: DTO restructure
URL: https://github.com/apache/incubator-dubbo-ops/pull/123
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/AccessesController.java
 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/AccessesController.java
index 027b583..389f4fa 100644
--- 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/AccessesController.java
+++ 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/AccessesController.java
@@ -20,7 +20,7 @@
 import com.alibaba.dubbo.common.logger.LoggerFactory;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.dubbo.admin.dto.AccessDTO;
-import org.apache.dubbo.admin.governance.service.ProviderService;
+import org.apache.dubbo.admin.dto.BaseDTO;
 import org.apache.dubbo.admin.governance.service.RouteService;
 import org.apache.dubbo.admin.registry.common.domain.Route;
 import org.apache.dubbo.admin.registry.common.route.RouteRule;
@@ -37,20 +37,16 @@
 
     @Resource
     private RouteService routeService;
-    @Resource
-    private ProviderService providerService;
 
-    @RequestMapping("/search")
-    public List<AccessDTO> searchAccess(@RequestBody(required = false) 
Map<String, String> params) throws ParseException {
+    @RequestMapping(value = "/search", method = RequestMethod.GET)
+    public List<AccessDTO> searchAccess(@RequestParam(required = false) String 
service) throws ParseException {
         List<AccessDTO> result = new ArrayList<>();
         List<Route> routes = new ArrayList<>();
-        if (StringUtils.isNotBlank(params.get("service"))) {
-            Route route = 
routeService.getBlackwhitelistRouteByService(params.get("service").trim());
+        if (StringUtils.isNotBlank(service)) {
+            Route route = 
routeService.getBlackwhitelistRouteByService(service.trim());
             if (route != null) {
                 routes.add(route);
             }
-        } else {
-            //TODO throw exception
         }
 
         for (Route route : routes) {
@@ -67,15 +63,34 @@
                 result.add(accessDTO);
             }
         }
+
         return result;
     }
 
+    @RequestMapping(value = "/detail", method = RequestMethod.GET)
+    public AccessDTO detailAccess(@RequestParam Long id) throws ParseException 
{
+        Route route = routeService.findRoute(id);
+        if (route.getName().endsWith(AccessDTO.KEY_BLACK_WHITE_LIST)) {
+            AccessDTO accessDTO = new AccessDTO();
+            accessDTO.setId(route.getId());
+            accessDTO.setService(route.getService());
+            Map<String, RouteRule.MatchPair> when = 
RouteRule.parseRule(route.getMatchRule());
+            for (String key : when.keySet()) {
+                accessDTO.setWhitelist(when.get(key).getUnmatches());
+                accessDTO.setBlacklist(when.get(key).getMatches());
+            }
+            return accessDTO;
+        } else {
+            return null;
+        }
+    }
+
     @RequestMapping(value = "/delete", method = RequestMethod.POST)
-    public void deleteAccess(@RequestBody Map<String, Long> params) {
-        if (params.get("id") == null) {
+    public void deleteAccess(@RequestBody BaseDTO baseDTO) {
+        if (baseDTO.getId() == null) {
             throw new IllegalArgumentException("Argument of id is null!");
         }
-        routeService.deleteRoute(params.get("id"));
+        routeService.deleteRoute(baseDTO.getId());
     }
 
     @RequestMapping(value = "/create", method = RequestMethod.POST)
diff --git 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/AccessDTO.java 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/AccessDTO.java
index 94c06ff..c739ed1 100644
--- 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/AccessDTO.java
+++ 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/AccessDTO.java
@@ -18,23 +18,14 @@
 
 import java.util.Set;
 
-public class AccessDTO {
+public class AccessDTO extends BaseDTO {
     // BlackWhiteList key
     public static final String KEY_BLACK_WHITE_LIST = "blackwhitelist";
 
-    private Long id;
     private String service;
     private Set<String> whitelist;
     private Set<String> blacklist;
 
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
     public String getService() {
         return service;
     }
diff --git 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/BaseDTO.java 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/BaseDTO.java
new file mode 100644
index 0000000..a7e9e77
--- /dev/null
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/BaseDTO.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.admin.dto;
+
+/**
+ * BaseDTO
+ *
+ * For receive ID parameter with @RequestBody
+ */
+public class BaseDTO {
+    private Long id;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+}
diff --git a/dubbo-admin-frontend/src/components/AccessControl.vue 
b/dubbo-admin-frontend/src/components/AccessControl.vue
index 500dac5..42fb311 100644
--- a/dubbo-admin-frontend/src/components/AccessControl.vue
+++ b/dubbo-admin-frontend/src/components/AccessControl.vue
@@ -212,8 +212,10 @@ export default {
     search (filter) {
       this.loading = true
       this.$router.push({path: 'access', query: (filter !== '' ? {service: 
filter} : null)})
-      AXIOS.post('/access/search', {
-        service: filter
+      AXIOS.get('/access/search', {
+        params: {
+          service: filter
+        }
       }).then(response => {
         this.accesses = response.data
         this.loading = false


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to