DESKTOP-HN5QP3V\Administrator 3 hete
szülő
commit
d53fe1d465
4 módosított fájl, 40 hozzáadás és 0 törlés
  1. 14 0
      app/api/v1/channel.go
  2. 1 0
      app/router/router.go
  3. 16 0
      app/service/channel.go
  4. 9 0
      pkg/serializer/channel.go

+ 14 - 0
app/api/v1/channel.go

@@ -9,6 +9,20 @@ import (
 	"github.com/gin-gonic/gin"
 )
 
+func ChannelAll(c *gin.Context) {
+	var appG = app.Gin{C: c}
+	service := service.GameChannelService{}
+	if err := c.ShouldBind(&service); err == nil {
+		if res, err := service.All(); err != nil {
+			appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
+		} else {
+			appG.Response(http.StatusOK, e.SUCCESS, res)
+		}
+	} else {
+		appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
+	}
+}
+
 // ChannelList 渠道列表
 func ChannelList(c *gin.Context) {
 	var appG = app.Gin{C: c}

+ 1 - 0
app/router/router.go

@@ -25,6 +25,7 @@ func NewRouter() *gin.Engine {
 
 		apiv1.POST("version/check", v1.CheckVersion)
 		apiv1.POST("version/server", v1.ServerVersion)
+		apiv1.POST("channel/all", v1.ChannelAll)
 	}
 
 	webv1 := r.Group("/web/v1")

+ 16 - 0
app/service/channel.go

@@ -11,6 +11,22 @@ import (
 	"go.mongodb.org/mongo-driver/mongo/options"
 )
 
+type GameChannelService struct {
+}
+
+func (s *GameChannelService) All() (interface{}, error) {
+	filter := bson.M{}
+	coll := mgm.Coll(&channel.Channel{})
+
+	var list []channel.Channel
+	err := coll.SimpleFindWithCtx(context.Background(), &list, filter)
+	if err != nil {
+		return nil, err
+	}
+
+	return serializer.BuildChannelAll(list), nil
+}
+
 // ChannelListService 渠道列表
 type ChannelListService struct {
 	Name      string `form:"name" json:"name"`

+ 9 - 0
pkg/serializer/channel.go

@@ -40,3 +40,12 @@ func BuildChannelList(list []channel.Channel, total int) map[string]interface{}
 		"total": total,
 	}
 }
+
+// BuildChannelAll 构建渠道列表响应
+func BuildChannelAll(list []channel.Channel) []*ChannelResponse {
+	items := make([]*ChannelResponse, 0, len(list))
+	for i := range list {
+		items = append(items, BuildChannel(&list[i]))
+	}
+	return items
+}