tokers commented on a change in pull request #1606:
URL: https://github.com/apache/apisix-dashboard/pull/1606#discussion_r595835029
##########
File path: api/internal/handler/route/route.go
##########
@@ -379,12 +380,25 @@ func (h *Handler) Create(c droplet.Context) (interface{},
error) {
}
}
- ret, err := h.routeStore.Create(c.Context(), input)
+ // check name existed
+ ret, err := h.routeStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ return obj.(*entity.Route).Name == input.Name
+ },
+ })
+ if err != nil {
+ return &data.SpecCodeResponse{StatusCode:
http.StatusInternalServerError}, err
+ }
+ if ret.TotalSize > 0 {
+ return &data.SpecCodeResponse{StatusCode:
http.StatusBadRequest}, errors.New("route name is existed")
Review comment:
typo: "route name is existed" => "route name exists".
##########
File path: api/internal/handler/route/route.go
##########
@@ -489,12 +503,32 @@ func (h *Handler) Update(c droplet.Context) (interface{},
error) {
}
}
- ret, err := h.routeStore.Update(c.Context(), &input.Route, true)
+ // check name existed
+ ret, err := h.routeStore.List(c.Context(), store.ListInput{
Review comment:
All these logics are similar, can we abstract them to a common
interface/method, so that we can reduce the code complexity and redundency.
##########
File path: api/internal/handler/route/route.go
##########
@@ -379,12 +380,25 @@ func (h *Handler) Create(c droplet.Context) (interface{},
error) {
}
}
- ret, err := h.routeStore.Create(c.Context(), input)
+ // check name existed
+ ret, err := h.routeStore.List(c.Context(), store.ListInput{
Review comment:
Can we use interface like `Get` so that the check can be faster.
----------------------------------------------------------------
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]