nic-chen commented on a change in pull request #450:
URL: https://github.com/apache/apisix-dashboard/pull/450#discussion_r486000136



##########
File path: api/route/route_test.go
##########
@@ -0,0 +1,51 @@
+package route
+
+import (
+       "github.com/apisix/manager-api/conf"
+       "github.com/apisix/manager-api/service"
+       "net/http"
+       "testing"
+)
+
+// publish route
+func TestPublishRoute(t *testing.T) {
+
+       // create route
+       handler.Post(uriPrefix+"/routes").
+               Header("Authorization", token).
+               JSON(`{
+      "name":"api-test",
+      "desc":"",
+      "priority":0,
+      "protocols":["http"],
+      "hosts":["test1.com"],
+      "paths":["/*"],
+      "methods":["GET","HEAD","POST","PUT","DELETE","OPTIONS","PATCH"],
+      "status":false,
+      "upstream_protocol":"keep",
+      "plugins":{},
+      "uris":["/*"],
+      "vars":[],
+      "upstream":{"type":"roundrobin","nodes":{"127.0.0.1:443":1},
+      "timeout":{"connect":6000,"send":6000,"read":6000}},
+      "upstream_header":{}
+}`).Expect(t).
+               Status(http.StatusOK).
+               End()
+       route, _ := getRouteByName("api-test")
+
+       // publish route
+       handler.Put(uriPrefix + "/routes/" + route.ID.String() + 
"publish").Expect(t).Status(http.StatusOK).End()
+       // offline route
+       handler.Put(uriPrefix + "/routes/" + route.ID.String() + 
"offline").Expect(t).Status(http.StatusOK).End()
+
+}
+

Review comment:
       `offline` also requires test cases
   

##########
File path: api/script/db/schema.sql
##########
@@ -18,7 +18,7 @@ CREATE TABLE `routes` (
   `update_time` bigint(20),
   `route_group_id` varchar(64) NOT NULL,
   `route_group_name` varchar(64) NOT NULL,
-
+  `status` tinyint(1),

Review comment:
       deed a default value ​​for compatibility.

##########
File path: api/route/route.go
##########
@@ -34,11 +34,100 @@ func AppendRoute(r *gin.Engine) *gin.Engine {
        r.GET("/apisix/admin/routes/:rid", findRoute)
        r.GET("/apisix/admin/routes", listRoute)
        r.PUT("/apisix/admin/routes/:rid", updateRoute)
+       r.PUT("/apisix/admin/routes/:rid/publish", publishRoute)
        r.DELETE("/apisix/admin/routes/:rid", deleteRoute)
        r.GET("/apisix/admin/notexist/routes", isRouteExist)
+       r.PUT("/apisix/admin/routes/:rid/offline", offlineRoute)
        return r
 }
 
+func publishRoute(c *gin.Context) {
+       rid := c.Param("rid")
+       r := &service.Route{}
+       tx := conf.DB().Begin()
+       if err := tx.Model(&service.Route{}).Where("id = ?", 
rid).Update("status", true).Find(&r).Error; err != nil {
+               tx.Rollback()
+               e := errno.FromMessage(errno.RoutePublishError, err.Error())
+               logger.Error(e.Msg)
+               c.AbortWithStatusJSON(http.StatusInternalServerError, 
e.Response())
+               return
+       } else {
+               routeRequest := &service.RouteRequest{}
+               if err := json.Unmarshal([]byte(r.Content), routeRequest); err 
!= nil {
+                       tx.Rollback()
+                       e := errno.FromMessage(errno.RoutePublishError, 
err.Error())
+                       logger.Error(e.Msg)
+                       c.AbortWithStatusJSON(http.StatusInternalServerError, 
e.Response())
+                       return
+               }
+               arr := service.ToApisixRequest(routeRequest)
+               var resp *service.ApisixRouteResponse
+               if resp, err = arr.Create(rid); err != nil {

Review comment:
       a little confused about `Create`, it should be `Update` or something 
here. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to