forked from MartialBE/one-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.go
47 lines (37 loc) · 835 Bytes
/
group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package controller
import (
"net/http"
"one-api/model"
"github.com/gin-gonic/gin"
)
func GetGroups(c *gin.Context) {
groupNames := make([]string, 0)
userGroup := model.GlobalUserGroupRatio.GetAll()
for symbol, _ := range userGroup {
groupNames = append(groupNames, symbol)
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": groupNames,
})
}
func GetUserGroupRatio(c *gin.Context) {
userId := c.GetInt("id")
userSymbol := ""
if userId > 0 {
userSymbol, _ = model.CacheGetUserGroup(userId)
}
groupRatio := model.GlobalUserGroupRatio.GetAll()
UserGroup := make(map[string]*model.UserGroup)
for k, v := range groupRatio {
if v.Public || k == userSymbol {
UserGroup[k] = v
}
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": UserGroup,
})
}