Browse Source

feat(api): Add /device-group/accessible for 1.3.8

lejianwen 11 months ago
parent
commit
73f3056878
3 changed files with 36 additions and 10 deletions
  1. 26 4
      http/controller/api/group.go
  2. 7 6
      http/response/api/peer.go
  3. 3 0
      http/router/api.go

+ 26 - 4
http/controller/api/group.go

@@ -45,7 +45,7 @@ func (g *Group) Users(c *gin.Context) {
45 45
 		userList = service.AllService.UserService.ListByGroupId(u.GroupId, q.Page, q.PageSize)
46 46
 	}
47 47
 
48
-	var data []*apiResp.UserPayload
48
+	data := make([]*apiResp.UserPayload, 0, len(userList.Users))
49 49
 	for _, user := range userList.Users {
50 50
 		up := &apiResp.UserPayload{}
51 51
 		up.FromUser(user)
@@ -88,14 +88,14 @@ func (g *Group) Peers(c *gin.Context) {
88 88
 		users = service.AllService.UserService.ListIdAndNameByGroupId(u.GroupId)
89 89
 	}
90 90
 
91
-	namesById := make(map[uint]string)
92
-	userIds := make([]uint, 0)
91
+	namesById := make(map[uint]string, len(users))
92
+	userIds := make([]uint, 0, len(users))
93 93
 	for _, user := range users {
94 94
 		namesById[user.Id] = user.Username
95 95
 		userIds = append(userIds, user.Id)
96 96
 	}
97 97
 	peerList := service.AllService.PeerService.ListByUserIds(userIds, q.Page, q.PageSize)
98
-	var data []*apiResp.GroupPeerPayload
98
+	data := make([]*apiResp.GroupPeerPayload, 0, len(peerList.Peers))
99 99
 	for _, peer := range peerList.Peers {
100 100
 		uname, ok := namesById[peer.UserId]
101 101
 		if !ok {
@@ -103,6 +103,7 @@ func (g *Group) Peers(c *gin.Context) {
103 103
 		}
104 104
 		pp := &apiResp.GroupPeerPayload{}
105 105
 		pp.FromPeer(peer, uname)
106
+		//pp.DeviceGroupName = uname
106 107
 		data = append(data, pp)
107 108
 
108 109
 	}
@@ -111,3 +112,24 @@ func (g *Group) Peers(c *gin.Context) {
111 112
 		Data:  data,
112 113
 	})
113 114
 }
115
+
116
+// Device
117
+// @Tags 群组
118
+// @Summary 设备
119
+// @Description 机器
120
+// @Accept  json
121
+// @Produce  json
122
+// @Param page query int false "页码"
123
+// @Param pageSize query int false "每页数量"
124
+// @Param status query int false "状态"
125
+// @Param accessible query string false "accessible"
126
+// @Success 200 {object} response.DataResponse
127
+// @Failure 500 {object} response.Response
128
+// @Router /device-group/accessible [get]
129
+// @Security BearerAuth
130
+func (g *Group) Device(c *gin.Context) {
131
+	c.JSON(http.StatusOK, response.DataResponse{
132
+		Total: 0,
133
+		Data:  nil,
134
+	})
135
+}

+ 7 - 6
http/response/api/peer.go

@@ -32,12 +32,13 @@ https://github.com/rustdesk/rustdesk/blob/master/flutter/lib/common/hbbs/hbbs.da
32 32
 		  }
33 33
 */
34 34
 type GroupPeerPayload struct {
35
-	Id       string           `json:"id"`
36
-	Info     *PeerPayloadInfo `json:"info"`
37
-	Status   int              `json:"status"`
38
-	User     string           `json:"user"`
39
-	UserName string           `json:"user_name"`
40
-	Note     string           `json:"note"`
35
+	Id              string           `json:"id"`
36
+	Info            *PeerPayloadInfo `json:"info"`
37
+	Status          int              `json:"status"`
38
+	User            string           `json:"user"`
39
+	UserName        string           `json:"user_name"`
40
+	Note            string           `json:"note"`
41
+	DeviceGroupName string           `json:"device_group_name"`
41 42
 }
42 43
 type PeerPayloadInfo struct {
43 44
 	DeviceName string `json:"device_name"`

+ 3 - 0
http/router/api.go

@@ -79,6 +79,8 @@ func ApiInit(g *gin.Engine) {
79 79
 		gr := &api.Group{}
80 80
 		frg.GET("/users", gr.Users)
81 81
 		frg.GET("/peers", gr.Peers)
82
+		// /api/device-group/accessible?current=1&pageSize=100
83
+		frg.GET("/device-group/accessible", gr.Device)
82 84
 	}
83 85
 
84 86
 	{
@@ -88,6 +90,7 @@ func ApiInit(g *gin.Engine) {
88 90
 		//更新地址
89 91
 		frg.POST("/ab", ab.UpAb)
90 92
 	}
93
+
91 94
 	PersonalRoutes(frg)
92 95
 	//访问静态文件
93 96
 	g.StaticFS("/upload", http.Dir(global.Config.Gin.ResourcesPath+"/public/upload"))