mochengqian commented on code in PR #1477:
URL: https://github.com/apache/dubbo-admin/pull/1477#discussion_r3294809217


##########
pkg/console/handler/rule_version.go:
##########
@@ -0,0 +1,260 @@
+/*
+ * 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 handler
+
+import (
+       "errors"
+       "net/http"
+       "strconv"
+       "strings"
+
+       "github.com/gin-contrib/sessions"
+       "github.com/gin-gonic/gin"
+
+       "github.com/apache/dubbo-admin/pkg/common/bizerror"
+       consolectx "github.com/apache/dubbo-admin/pkg/console/context"
+       "github.com/apache/dubbo-admin/pkg/console/model"
+       "github.com/apache/dubbo-admin/pkg/console/service"
+       coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
+       "github.com/apache/dubbo-admin/pkg/core/versioning"
+)
+
+type rollbackReq struct {
+       Reason            string `json:"reason"`
+       ExpectedVersionID *int64 `json:"expectedVersionId"`
+}
+
+type abandonIntentReq struct {
+       Reason string `json:"reason"`
+}
+
+const maxRuleVersionReasonLength = 1024
+
+func ListRuleVersions(cs consolectx.Context, kind coremodel.ResourceKind) 
gin.HandlerFunc {
+       return func(c *gin.Context) {
+               if !ensureVersioningEnabled(c, cs) {
+                       return
+               }
+               resp, err := service.ListRuleVersions(cs, 
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name: 
c.Param("ruleName")})
+               writeVersioningResp(c, resp, err)
+       }
+}
+
+func GetRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind) 
gin.HandlerFunc {
+       return func(c *gin.Context) {
+               if !ensureVersioningEnabled(c, cs) {
+                       return
+               }
+               id, ok := parseVersionID(c)
+               if !ok {
+                       return
+               }
+               resp, err := service.GetRuleVersion(cs, 
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name: 
c.Param("ruleName")}, id)
+               writeVersioningResp(c, resp, err)
+       }
+}
+
+func DiffRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind) 
gin.HandlerFunc {
+       return func(c *gin.Context) {
+               if !ensureVersioningEnabled(c, cs) {
+                       return
+               }
+               id, ok := parseVersionID(c)
+               if !ok {
+                       return
+               }
+               resp, err := service.DiffRuleVersion(cs, 
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name: 
c.Param("ruleName")}, id, c.Query("against"))
+               writeVersioningResp(c, resp, err)
+       }
+}
+
+func RollbackRuleVersion(cs consolectx.Context, kind coremodel.ResourceKind) 
gin.HandlerFunc {
+       return func(c *gin.Context) {
+               if !ensureVersioningEnabled(c, cs) {
+                       return
+               }
+               id, ok := parseVersionID(c)
+               if !ok {
+                       return
+               }
+               req := rollbackReq{}
+               if err := c.ShouldBindJSON(&req); err != nil {
+                       c.JSON(http.StatusOK, 
model.NewBizErrorResp(bizerror.New(bizerror.InvalidArgument, err.Error())))
+                       return
+               }
+               if !validateRuleVersionReasonLength(c, req.Reason) {
+                       return
+               }
+               resp, err := service.RollbackRuleVersion(cs, 
service.RuleKindName{Kind: kind, Mesh: c.Query("mesh"), Name: 
c.Param("ruleName")}, id, req.Reason, req.ExpectedVersionID, currentUser(c))
+               writeVersioningResp(c, resp, err)
+       }
+}
+
+func RepairRuleVersionIntent(cs consolectx.Context) gin.HandlerFunc {
+       return func(c *gin.Context) {
+               if !ensureVersioningEnabled(c, cs) {
+                       return
+               }
+               id, ok := parseIntentID(c)
+               if !ok {
+                       return
+               }
+               resp, err := service.RepairRuleVersionIntent(cs, id)
+               writeVersioningResp(c, resp, err)
+       }
+}
+
+func AbandonRuleVersionIntent(cs consolectx.Context) gin.HandlerFunc {
+       return func(c *gin.Context) {
+               if !ensureVersioningEnabled(c, cs) {
+                       return
+               }
+               id, ok := parseIntentID(c)
+               if !ok {
+                       return
+               }
+               req := abandonIntentReq{}
+               if err := c.ShouldBindJSON(&req); err != nil {
+                       c.JSON(http.StatusOK, 
model.NewBizErrorResp(bizerror.New(bizerror.InvalidArgument, err.Error())))

Review Comment:
   Fixed in 74dfd5c. Malformed abandon-intent JSON now uses the same 
`InvalidArgument` response path and returns HTTP 400. The handler tests cover 
this alongside rollback binding errors and invalid id parsing.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to