liuxiran commented on a change in pull request #450:
URL: https://github.com/apache/apisix-dashboard/pull/450#discussion_r486072028
##########
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:
in this pr, we divided the process of creating a route into two steps:
create a route (without publish)only in mysql, and do `publish` to create a
route in apisix.
so here we use `create`
----------------------------------------------------------------
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:
[email protected]