GetSpaces godoc @Summary 获取空间列表 @Description 获取用户所属的空间列表,支持状态筛选和名称模糊查询 @Tags 空间管理 @Accept json @Produce json @Security BearerAuth @Param status query int false "空间状态(-1:全部,0:active,1:archived)" default(-1) Enums(-1,0,1) @Param name query string false "空间名称模糊查询" @Param offset query int false "分页偏移量,默
(c *gin.Context)
| 102 | // @Success 200 {object} model.CommonResponse{data=model.SpaceListResponse} "Success" |
| 103 | // @Router /api/spaces [get] |
| 104 | func GetSpaces(c *gin.Context) { |
| 105 | eid := config.GetEID(c) |
| 106 | userID := config.GetUserId(c) |
| 107 | |
| 108 | // 检查功能是否可用 |
| 109 | params := map[string]interface{}{ |
| 110 | "from": "space", |
| 111 | } |
| 112 | _, err := service.IsFeatureAvailable(c, "knowledge_base", params) |
| 113 | if err != nil { |
| 114 | c.JSON(http.StatusForbidden, model.FeatureNotAvailableError.ToResponse(err)) |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | statusStr := c.Query("status") |
| 119 | status := -1 |
| 120 | if statusStr != "" { |
| 121 | if s, err := strconv.Atoi(statusStr); err == nil { |
| 122 | status = s |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | view := c.Query("view") |
| 127 | |
| 128 | // 解析名称模糊查询参数 |
| 129 | name := c.Query("name") |
| 130 | |
| 131 | // 解析分页参数 |
| 132 | offsetStr := c.Query("offset") |
| 133 | offset := 0 |
| 134 | if offsetStr != "" { |
| 135 | if o, err := strconv.Atoi(offsetStr); err == nil { |
| 136 | offset = o |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | limitStr := c.Query("limit") |
| 141 | limit := 10 |
| 142 | if limitStr != "" { |
| 143 | if l, err := strconv.Atoi(limitStr); err == nil { |
| 144 | limit = l |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // 获取空间服务 |
| 149 | sps := service.NewSpacePermissionService(eid) |
| 150 | |
| 151 | var count int64 |
| 152 | var spaces []model.Space |
| 153 | var err2 error |
| 154 | if view == "user" { |
| 155 | // 获取用户所属的空间(带筛选条件和分页) |
| 156 | count, spaces, err2 = sps.GetUserSpaces(userID, status, name, offset, limit) |
| 157 | } else { |
| 158 | if !common.IsAdmin(c) { |
| 159 | c.JSON(http.StatusForbidden, model.AuthFailed.ToResponse(nil)) |
| 160 | return |
| 161 | } |
nothing calls this directly
no test coverage detected