UpdateGroup handles updating an existing group.
(c *gin.Context)
| 167 | |
| 168 | // UpdateGroup handles updating an existing group. |
| 169 | func (s *Server) UpdateGroup(c *gin.Context) { |
| 170 | id, err := strconv.Atoi(c.Param("id")) |
| 171 | if err != nil { |
| 172 | response.ErrorI18nFromAPIError(c, app_errors.ErrBadRequest, "validation.invalid_group_id") |
| 173 | return |
| 174 | } |
| 175 | |
| 176 | var req GroupUpdateRequest |
| 177 | if err := c.ShouldBindJSON(&req); err != nil { |
| 178 | response.Error(c, app_errors.NewAPIError(app_errors.ErrInvalidJSON, err.Error())) |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | params := services.GroupUpdateParams{ |
| 183 | Name: req.Name, |
| 184 | DisplayName: req.DisplayName, |
| 185 | Description: req.Description, |
| 186 | GroupType: req.GroupType, |
| 187 | ChannelType: req.ChannelType, |
| 188 | Sort: req.Sort, |
| 189 | ValidationEndpoint: req.ValidationEndpoint, |
| 190 | ParamOverrides: req.ParamOverrides, |
| 191 | ModelRedirectRules: req.ModelRedirectRules, |
| 192 | ModelRedirectStrict: req.ModelRedirectStrict, |
| 193 | Config: req.Config, |
| 194 | ProxyKeys: req.ProxyKeys, |
| 195 | } |
| 196 | |
| 197 | if req.Upstreams != nil { |
| 198 | params.Upstreams = req.Upstreams |
| 199 | params.HasUpstreams = true |
| 200 | } |
| 201 | |
| 202 | if req.TestModel != "" { |
| 203 | params.TestModel = req.TestModel |
| 204 | params.HasTestModel = true |
| 205 | } |
| 206 | |
| 207 | if req.HeaderRules != nil { |
| 208 | rules := req.HeaderRules |
| 209 | params.HeaderRules = &rules |
| 210 | } |
| 211 | |
| 212 | group, err := s.GroupService.UpdateGroup(c.Request.Context(), uint(id), params) |
| 213 | if s.handleGroupError(c, err) { |
| 214 | return |
| 215 | } |
| 216 | |
| 217 | response.Success(c, s.newGroupResponse(group)) |
| 218 | } |
| 219 | |
| 220 | // ReorderGroups handles batch reorder updates for groups. |
| 221 | func (s *Server) ReorderGroups(c *gin.Context) { |
nothing calls this directly
no test coverage detected