You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/09/19 02:15:11 UTC

[GitHub] [apisix-dashboard] ShiningRush commented on a change in pull request #486: feat: add consumer CURD refactoring

ShiningRush commented on a change in pull request #486:
URL: https://github.com/apache/apisix-dashboard/pull/486#discussion_r491256497



##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -0,0 +1,135 @@
+package consumer
+
+import (
+	"reflect"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	consumerStore *store.GenericStore
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	s, err := store.NewGenericStore(store.GenericStoreOption{
+		BasePath: "/apisix/consumers",
+		ObjType:  reflect.TypeOf(entity.Consumer{}),
+		KeyFunc: func(obj interface{}) string {
+			r := obj.(*entity.Consumer)
+			return r.Username
+		},
+	})
+	if err != nil {
+		return nil, err
+	}
+	if err := s.Init(); err != nil {
+		return nil, err
+	}
+
+	utils.AppendToClosers(s.Close)
+	return &Handler{
+		consumerStore: s,
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/apisix/admin/consumers/:id", wgin.Wraps(h.Get,
+		wrapper.InputType(reflect.TypeOf(GetInput{}))))
+	r.GET("/apisix/admin/consumers", wgin.Wraps(h.List,
+		wrapper.InputType(reflect.TypeOf(ListInput{}))))
+	r.POST("/apisix/admin/consumers", wgin.Wraps(h.Create,
+		wrapper.InputType(reflect.TypeOf(entity.Consumer{}))))
+	r.PUT("/apisix/admin/consumers/:id", wgin.Wraps(h.Update,
+		wrapper.InputType(reflect.TypeOf(UpdateInput{}))))
+	r.DELETE("/apisix/admin/consumers", wgin.Wraps(h.BatchDelete,

Review comment:
       Yes




----------------------------------------------------------------
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:
users@infra.apache.org